【发布时间】:2016-08-07 10:48:05
【问题描述】:
子路由内的辅助路由,不知道如何设置让它工作。 我有根组件和路由配置文件,例如:
root.routes.ts
export const rootRoute:RouterConfig=[
...ChildrenRoute,
{path:'',component:ChildrenRootComponent},
{path:'children-root',component:ChildrenRootComponent},
{path:'other',component:OtherComponent'}
];
template:
'<a routerLink='children-root'>Children root</a>
<a routerLink='other'>Other</a>
<router-outlet></router-outlet>'
和 ChildrenRootComponent 有 FirstComponent 和 SecondComponent 与路由配置文件,如:
children.routes.ts
export const ChildrenRoute:RouterConfig=[
{path:"",redirectTo:'/children-root',pathMatch:'full'},
{path:'children-root',component:ChildrenRootComponent,
children:[
{path:'',component:FirstComponent},
{path:'first',component:FirstComponent},
{path:'second',component:SecondComponent,outlet:'aux'}
]
}
];
template:
' <a routerLink='first'>First</a>
<router-outlet></router-outlet>
<a routerLink='aux:second'>Second</a>
<router-outlet name="aux"></router-outlet>'
现在从 Children root -> Second 的路线没问题,但是路线 Children root -> first 不起作用显示错误:
Error: Cannot match any routes: 'children-root/second'
更改模板:
' <a routerLink='first'>First</a>
<router-outlet></router-outlet>
<a routerLink='(aux:second)'>Second</a>
<router-outlet name="aux"></router-outlet>'
也不行。错误:
Error: Cannot match any routes: 'children-root/second)'
这里注意错误信息中的')',不要有'('。 在浏览器中直接设置url如下
localhost:4200/children-root/(aux:second)
重新加载并运行良好。所以我想我设置 routerLink 错误,搜索了很多,没有找到任何关于这个的。
【问题讨论】: