【问题标题】:Angular routerlink using semicolon instead of question mark, url not behaving as expectedAngular routerlink 使用分号而不是问号,url 的行为不符合预期
【发布时间】:2021-11-16 12:29:21
【问题描述】:

我的代码中有以下按钮:

<button [routerLink]="['/answerslist', {id: applicant.id} ]" label="View Interview"></button> 

对应如下路线:

{ path: 'answerslist', component: AnswersListComponent },

我希望 URL 如下所示: http://localhost:4200/answerslist?id=member2

但是我在点击按钮时得到了这个: http://localhost:4200/answerslist;id=member2

(分号代替问号)

因此,代码无法正常工作。我正在检索参数以供以后使用,如下所示:

  getUser(){
    this.activeRoute.queryParams.subscribe(
      (params) => {
        const id = params['id'];
        if (id) { 
          this.currentUser = id;
        }
        else{
          console.log('id not passed'); //this is what currenlty gets printed
        }
      });
  }

所以我需要一种方法来构造带有问号而不是分号的 URL

【问题讨论】:

    标签: angular url routes


    【解决方案1】:

    请试试这个

    < button [routerLink]="['answerslist']" [queryParams]="{ id: applicant.id }"></button >
    

    更多信息请访问https://angular.io/api/router/RouterLink

    【讨论】:

      猜你喜欢
      • 2018-12-04
      • 2018-12-21
      • 2021-04-26
      • 2017-01-07
      • 2017-11-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-12
      相关资源
      最近更新 更多