2016-09-28 113 views
0

我需要在應用的每條路由之前添加文化。我仍然在使用RC4。 如何修改當前的路線以達到理想的效果?帶文化的角度2路由

export const routes: RouterConfig = [ 
...ItemRoutes, 
...LibraryRoutes, 

{ path: '', redirectTo: 'dashboard', pathMatch: 'full' }, 
{ path: 'dashboard', component: DashboardComponent }, 
{ path: '**', redirectTo: 'dashboard' } 

];

現在的身份驗證後,我的重定向鏈接是

localhost/en 

我有難同當應用程序組件加載當前區域性的應用程序配置,最終我想設置的語言那裏,它作爲一個前綴路由。

使用我當前的設置,我將重定向到儀表板。 如何將文化參數作爲第一個參數添加到所有路線? 有什麼我應該知道的路線和文化/語言設置?什麼是在前端設置語言的最佳方式?

回答

1

下面的解決方案是不完全添加前綴的所有路線,但它可能會幫助,

export const routes: RouterConfig = [ 
...ItemRoutes, 
...LibraryRoutes, 

{ path: '', redirectTo: 'dashboard', pathMatch: 'full' }, 
{ path: 'dashboard', component: DashboardComponent }, 
{ path: '**', redirectTo: 'dashboard' } 
] 

export const localeRoutes: RouterConfig = [ 
{ path: '', redirectTo: 'en' , pathMatch: 'full'}, 
{ path: 'en', children: routes }, 
{ path: 'fr', children: routes } 
] 

你必須確保所有的路線都是從這裏只配置,如果路由被導入模塊中定義,他們將分開處理。但是,如果在此處配置,此方法將適用於Lazy加載的路線。

希望這有助於!