简体   繁体   English

使用NavigationByUrl时,queryParams不会反映在URL中

[英]queryParams are not reflected in URL while using navigateByUrl

In my component, when I try 在我的组件中,当我尝试

this.router.navigate([`/courses/`, course.id], {queryParams:{description: course.description}});

After navigation, URL has description query parameter. 导航后,URL具有description查询参数。

But, when I try this one, 但是,当我尝试这个

this.router.navigateByUrl(`/courses/${course.id}`, {queryParams:{description: course.description}});

URL does not have description query parameter inside it. URL内没有description查询参数。

Do I need to make changes to reflect my query parameter inside the URL while using navigateByUrl ? 我是否需要作出改变,同时使用,以反映URL里面我的查询参数navigateByUrl (But, Angular Documentation says that NavigationExtras object is same for both navigate and navigateByUrl .) (但是, 角文档说, NavigationExtras对象是相同的两个navigatenavigateByUrl 。)

It seems query params are ignored by navigateByUrl method and documentation is not clear enough. 似乎查询参数被navigateByUrl方法忽略,并且文档不够清楚。 Take a look at those links for more info: link 1 link 2 . 查看这些链接以获取更多信息: 链接1 链接2

As a workaround you can try this 作为解决方法,您可以尝试一下

this.router.navigateByUrl(
  this.router.createUrlTree(
    ['some/route'], {queryParams: myParamObject}
  );
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM