2017-02-10 167 views
2

AM設置模塊在我的路由,我想設置默認路由,但它不能Angular2設置默認路由

這是路由模塊

const appRoutes: Routes = [ 
{ path: 'login', component: LoginComponent, useAsDefault:true }, //returns an error 
{ 
    path: 'dash', 
    redirectTo:"dashboard" 
}, 

{ path: 'reset-password', component: ResetPasswordComponent }, 
{ path: '', redirectTo: '/dashboard', pathMatch: 'full' }, 
{ path: '**', component: PageNotFoundComponent } 
]; 

以上返回

錯誤
LoginComponent; useAsD...' is not assignable to type 'Route[]' 

什麼可能是錯的

+0

請看看http://stackoverflow.com/questions/37605119/angular2-router-angular-router-how-to-set-default-route –

+0

有什麼不對?你有錯誤的清晰的反應;)因爲路由器沒有'useAsDefault'屬性,檢查它:https://angular.io/docs/ts/latest/api/router/index/Route-interface.html – Daredzik

回答

6

當使用useAsDefault時,您需要有父項路線和您想要​​首先出現的子路線上的useAsDefault。 因此,無需useAsDefault的,你可以簡單地給出登錄爲默認Routes.And當我看到有對儀表板所以沒有采用進口部件,

const appRoutes: Routes = [ 
    { 
    path: '', 
    redirectTo: "/login", 
    pathMatch: 'full' 
    }, 
    { path: 'login', component: LoginComponent }, 
    { path: 'reset-password', component: ResetPasswordComponent }, 
    { path: '**', component: PageNotFoundComponent } 
];