![](/img/trans.png)
[英]Angular2 - when changing route I get a systemJs error for load children route
[英]Angular 2 and SystemJS child route access error
我有一個帶有以下路線的angular 2應用程序:
export const MODULE_ROUTES: Route[] =[
{ path: '', redirectTo: 'dashboard', pathMatch: 'full' },
{ path: 'dashboard', component: HomeComponent, canActivate: [AuthGuard] },
{ path: 'user', component: UserComponent, canActivate: [AuthGuard] },
{ path: 'table', component: TableComponent, canActivate: [AuthGuard] },
{ path: 'icons', component: IconsComponent, canActivate: [AuthGuard] },
{ path: 'notifications', component: NotificationsComponent, canActivate: [AuthGuard] },
{ path: 'typography', component: TypographyComponent, canActivate: [AuthGuard] },
{ path: 'maps', component: MapsComponent, canActivate: [AuthGuard] },
{ path: 'upgrade', component: UpgradeComponent, canActivate: [AuthGuard] },
{ path: 'calendar', component: CalendarComponent, canActivate: [AuthGuard] },
{ path: 'login', component: LoginComponent },
{ path: 'unauthorized', component: UnauthorizedComponent },
{ path: 'adminarea',component: AdminareaComponent, canActivate: [AuthGuard],
children: [
{
path:'test1', component: CalendarComponent
}
] },
{ path: '**', component: DashboardComponent }
]
我的index.html文件上有<base href='/'
>。 另外,我的組件上也有<router-outlet>
標簽。
如果我在瀏覽器上放:
http://localhost:8000/adminarea
或http://localhost:8000/dashboard
頁面和路由正常顯示。 但是,如果我輸入http://localhost:8000/adminarea/test1
則該頁面被奇怪的錯誤破壞了:
如果我在瀏覽器地址欄上放置了任何父級的子路由(或子級),則會出現同樣的錯誤和行為。 例如:
http://localhost:8000/dashboard/xyz
但是,如果我有{ path: '**', component: DashboardComponent }
不應該重定向到我的DashboardComponent(如果是404路由)? 為什么我的孩子的路線“ test1”不起作用?
你能幫我嗎?
問題是命名為子<router-outlet>
。
在我的子組件上,我有一個命名的路由器出口<router-outlet name="adminarea"></router-outlet>
。 我刪除了“名稱” ,現在一切正常。 但是我不明白為什么。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.