【问题标题】:Angular remove query param when call back button回调按钮时角度删除查询参数
【发布时间】:2020-01-11 06:07:29
【问题描述】:

我需要检查我的收入 URL 是否是特定格式,然后打开模态并做一些事情。我用这段代码来做这个:

route.queryParams.subscribe(async params => {
      if (!isNaN(params.rt)) {
        console.log("URL Match");
        this.show = true;
      } else {
        console.log("URL does not Match");
      }
    });

我的格式应该是这样的:

www.example.com?=123456

但我需要如果完成模态过程,删除查询参数从 url

【问题讨论】:

    标签: angular typescript url angular-routing


    【解决方案1】:

    要删除查询参数,您可以执行以下操作。

    let url: string = this.router.url.substring(0, this.router.url.indexOf("?"));
    this.router.navigateByUrl(url); // where this.router will be intialized in ex:// constructor(private router:Router) {}
    

    此链接可能会有所帮助。

    cleary query params in router (SO)

    【讨论】:

      猜你喜欢
      • 2012-02-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-15
      • 1970-01-01
      • 2018-07-11
      相关资源
      最近更新 更多