Vla*_* S. 4 javascript frontend typescript angular-ui-router angular
有没有一种方法可以处理递归未知的确切数量的路由器参数?
例如:
我们有产品类别,可以有子类别,子类别可以有自己的子类别,依此类推。有几个主要条件:
/categories/{id}/items该类别,这将打开项目列表组件。/categories/{id}/{id}/.../{id},该级别应打开最后一个categoryId子类别列表组件。/categories/{id}/{id}/.../{id}/items。检查和重定向的解决方案是拥有路由器解析器。但是如何在路由模块中跟踪这些网址?
在我看来,路线应如下所示:
{
path: '/categories/:id',
component: SubcategoriesListComponent
},
{
path: '/categories/:id/**/:id',
component: SubcategoriesListComponent,
},
{
path: '/categories/:id/**/:id/items',
component: CategoryItemsListComponent
}
Run Code Online (Sandbox Code Playgroud)
有可能以这种方式实施吗?
无组件路由的可能解决方案:在路由配置中
{
path: 'categories/:id', children: [
{path: '**', component: SubcategoriesListComponent}
]
}
Run Code Online (Sandbox Code Playgroud)
在组件文件中:
export class SubcategoriesListComponent {
constructor(aroute: ActivatedRoute) {
aroute.url.subscribe((data) => {
console.log('params ', data); //contains all the segments so put logic here of determining what to do according to nesting depth
});
}
}
Run Code Online (Sandbox Code Playgroud)
这是输出示例(我在我的项目ErrorComponent上进行了测试,所以请不要混淆)
| 归档时间: |
|
| 查看次数: |
964 次 |
| 最近记录: |