我有这样的路由

{
    path: ':fundHouseName',
    pathMatch: 'full',
    children: [{
        path: RoutePaths.funds,
        component: FundsComponent,
        canActivate: [AuthGuard]
    }]
},
{
    path: '',
    children: [{
        path: RoutePaths.funds,
        component: FundsComponent,
        canActivate: [AuthGuard]
    }]
},

我想要的是这条路由应该与参数路由(第一条路由)相匹配

https://localhost:4200/Kotak/funds

并且这应该与非参数的路由(第二条路由)相匹配

https://localhost:4200/funds

但是这两条路由都与参数1匹配,而我在参数路由上设置了pathMatch:'full',因此我的理解是,在路由满之前,它不应该与参数路由匹配,也就是说,路由应该有:fundHouseName部分,然后是funds部分,因此基本上路径必须是这样的满路径

XYZ/funds

我对pathMatch的理解错了吗?

我如何才能做到这一点呢?

推荐答案

[{
    path: '',
    children: [{
        path: RoutePaths.funds,
        component: FundsComponent,
        canActivate: [AuthGuard]
    }]
},
{
    path: ':fundHouseName',
    children: [{
        path: RoutePaths.funds,
        component: FundsComponent,
        canActivate: [AuthGuard]
    }]
},]

只需交换可以解决问题的订单即可.

ANGLE路由将始终匹配第一个可能的值,因此您需要框显列表值,以便为所有可能的场景匹配正确的值

Https://localhost:4200/Kotak/funds->;将不匹配第一条路由,因为存在Kotak,因此它将跳转到下一条路由

Https://localhost:4200/funds-&>将在第一条路由上匹配,因此不会跨越到第二条路由

注意:pathmatchfull在这个方法中也不是必须的,所以我删除了它

Angular相关问答推荐

第15角Cookie的单元测试用例

Angular 环境本地无文件替换

Angular 如何渲染ngFor?

Angular 如何观察DOM元素属性的变化?

从Angular 前端访问ASP.NET Core 8 Web API时出现CORS错误

P-DropDown不会使用react 式表单手动设置Value

react 形式之间的循环关系

有角.服务.模块构建失败.无法读取未定义的属性(读取文件)

Cypress 12.8.1 无法使用条纹元素 iframe

Angular 在关闭另一个对话框后打开另一个对话框的最佳做法是什么?

导入 AngularFirestoreModule 时出现问题:此类型参数可能需要 `extends firebase.firestore.DocumentData` 约束.

TypeError:this.restoreDialogRef.afterClosed 不是函数

根据变量值更改按钮样式

如何在 Angular4 中访问组件的 nativeElement?

material Angular手风琴header/title高度

@HostBinding 与 Angular 中的变量类

RxJS:takeUntil() Angular 组件的 ngOnDestroy()

输入更改时Angular2动态输入字段失go 焦点

RxJS - 发生错误时观察到的不会完成

Angular2:无法读取未定义的属性名称