【问题标题】:Preserve param when using router link使用路由器链接时保留参数
【发布时间】:2020-10-13 17:20:38
【问题描述】:

有没有办法在保持当前 url 结尾的同时实现路由更改?示例:

我有一个这样定义的路线:/detail/:user-name/:activity-name 我希望能够使用 RouterLink 指令来实现以下操作:

从 /detail/tom/resume 移动 --> /detail/alex/resume(更新用户名参数但保持活动名称参数不变)

谢谢。

【问题讨论】:

    标签: angular


    【解决方案1】:

    也许你可以这样尝试(未测试):

    activityName = this.route.snapshot.paramMap.get('activity-name');
    detail = this.route.snapshot.paramMap.get('detail');
    
    constructor(private route: ActivatedRoute) {}
    
    <a [routerLink]="[detail, 'tom', activityName]">Tom details</a>
    <a [routerLink]="[detail, 'alex', activityName]">Alexdetails</a>
    

    【讨论】:

    • 可能有效,但我正在使用模板内的指令搜索解决方案
    猜你喜欢
    • 1970-01-01
    • 2018-04-30
    • 1970-01-01
    • 2023-04-01
    • 2018-02-04
    • 1970-01-01
    • 2020-06-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多