2016-10-27 48 views
1
哈希

我的包JSON有"@angular/router": "3.0.0"角2路由器3.0.0仍然顯示/#/上航線

我的應用程序路徑:

export const routeConfig: Routes = [ 
    {path: '', redirectTo: 'use-cases', pathMatch: 'full'}, 
    {path: 'use-cases', component: UseCasesComponent}, 
    {path: 'add', component: AddComponent}, 
    {path: 'github', component: RepoBrowserComponent, 
    children: [ 
     {path: '', component: RepoListComponent}, 
     {path: ':org', component: RepoListComponent, 
     children: [ 
      {path: '', component: RepoDetailComponent}, 
      {path: ':repo', component: RepoDetailComponent} 
     ] 
     }] 
    } 
]; 

但是,當我訪問我的應用程序仍然得到/#/的基礎上的網址。

+3

您是否在某處啓用了'HashLocationStrategy'? –

回答

1

默認使用的角度爲PathLocationStrategy(無/#/)。

如果您提供您的代碼

providers: [{provide: LocationStrategy, useClass: HashLocationStrategy}] 

某處路由器使用/#/

這通常是因爲當使用不支持HTML5 pushState支持的服務器時,PathLocationStrategy導致404錯誤。 如果你的服務器支持HTML5 pushState,只需刪除上述提供商。