2017-02-10 171 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 } 
];