2016-03-14 45 views
2

我用chsakell的this例子,用角度2玩了一下。如何在這個角度2樣本上使用HTML5模式?

我試圖做的是,以取代「散列」網址,以真實的URL(http://localhost:9823/#/photoshttp://localhost:9823/photos例如)

根據this鏈接的第一件事情,我都用PathLocationStrategy,這是默認的路由策略。

爲了做到這一點,我通過

bootstrap(AppRoot, [HTTP_PROVIDERS, ROUTER_PROVIDERS, 
    provide(RequestOptions, { useClass: AppBaseRequestOptions }), 
    provide(APP_BASE_HREF, { useValue: '/' }), 
    DataService, MembershipService, UtilityService]) 
    .catch(err => console.error(err)); 

改變了這種

bootstrap(AppRoot, [HTTP_PROVIDERS, ROUTER_PROVIDERS, 
    provide(RequestOptions, { useClass: AppBaseRequestOptions }), 
    provide(LocationStrategy, { useClass: HashLocationStrategy }), 
    DataService, MembershipService, UtilityService]) 
    .catch(err => console.error(err)); 

但是哈希仍然顯示。我如何擺脫Angular 2的網址哈希值?

回答

1

清空瀏覽器緩存或強制重新加載ctrl + F5

0

僅供參考,

... 
import {Component,bind} from 'angular2/core'; 
import {Router,ROUTER_PROVIDERS,RouteConfig, ROUTER_DIRECTIVES,APP_BASE_HREF,LocationStrategy,RouteParams,ROUTER_BINDINGS} from 'angular2/router'; 


bootstrap(AppRoot, [HTTP_PROVIDERS, ROUTER_PROVIDERS, 
      provide(RequestOptions, { useClass: AppBaseRequestOptions }), 
      bind(APP_BASE_HREF).toValue(location.pathname), 
      DataService, MembershipService, UtilityService]) 
      .catch(err => console.error(err));