简体   繁体   English

Angular2设置默认路由

[英]Angular2 setting default route

Am setting my routing in the module and i would like to set default route but it fails 我在模块中设置我的路由,我想设置默认路由,但它失败了

This is the routing module 这是路由模块

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 }
];

The above returns an error of 以上返回错误

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

What could be wrong 可能有什么不对

When using useAsDefault you need to have the parent route and the useAsDefault on the child route you want to appear first. 使用useAsDefault时,您需要在要首先显示的子路由上使用父路由和useAsDefault。 So, No need of useAsDefault, You can simply gives Login As Default Routes.And As I see there is no Imported component for Dashboard so, 所以,不需要使用AsDefault,你可以简单地给Login As Default Routes.And,因为我看到没有为Dashboard导入的组件,所以,

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM