【问题标题】:Angular with query params with percent (%2) not rendering page带有百分比(%2)的查询参数的角度不呈现页面
【发布时间】:2020-06-11 17:14:22
【问题描述】:

我不知道如何使用查询参数不呈现 Angular 视图来解决这个问题。我已经从后端对字符串进行了编码。

这不起作用:

http://localhost:2333/change-password?token=cfdj8ka%2bqsu

这行得通:

http://localhost:2333/change-password?token=cfdj8ka
http://localhost:2333/change-password?token=cfdj8kabqsu

我相信 %2 是/ 的编码值。如何让我的 Angular 路线正确解码?我正在使用 Angular 5。

【问题讨论】:

    标签: angular angular-ui-router


    【解决方案1】:

    可能你正在使用 this.router.navigate([url]) 而不是那个使用

    this.router.navigateByUrl(url);

    在构造函数中

    constructor(private _route: ActivatedRoute,) { 
       let token= this._route.snapshot.queryParamMap.get('token');
    }
    

    【讨论】:

    • 不,我是直接在浏览器上打开网址。
    • 你想从 ts 文件中的 url 获取什么查询参数?
    • 由于 %2f.如果确实加载了,我可以在我的组件中检索令牌。
    • 你试过这个吗?_route.snapshot.queryParamMap.get('token');在 _route 是私有 _route 的构造函数中:ActivatedRoute,
    • 我暂时删除了获取查询参数的代码,但它甚至没有渲染组件。好像没有找到路径什么的。
    猜你喜欢
    • 2017-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-23
    • 1970-01-01
    • 1970-01-01
    • 2019-06-21
    相关资源
    最近更新 更多