簡體   English   中英

Angular2設置默認路由

[英]Angular2 setting default route

我在模塊中設置我的路由,我想設置默認路由,但它失敗了

這是路由模塊

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[]'

可能有什么不對

使用useAsDefault時,您需要在要首先顯示的子路由上使用父路由和useAsDefault。 所以,不需要使用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