繁体   English   中英

Angular 2和SystemJS子路由访问错误

[英]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/adminareahttp://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.

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