繁体   English   中英

Angular 9条动态路由

[英]Angular 9 dynamic routes

首先抱歉我的英语不太好,但我会试着解释一下自己,我正在 Angular 9 中创建一个电子商务,这个电子商务的路线如下,最后的每条路线都是.html I直接到我称为路由器重定向的组件,当我落入该组件时,我将电子商务称为 api 传递有问题的 url 然后它返回如果该 Z572D4E421E5E6B9BC11D815E8A021 是一个重定向的产品类别。正确的组件。

The problem is that in certain situations like the categories page I need to leave some query strings like pageIndex and orderby in the URL but angular does not show the query strings because when I do the navigate I put skipLocationChange: true because I cannot change the url我需要保留查询字符串。

我只在用户想与其他人共享 url 时才需要它。

我如何执行导航方法的示例:

this.router.navigate(['categoria-listagem'], {
      skipLocationChange: true,
      queryParams: { page: 1, order: 'novidades' }
});

请如果有人知道执行此重定向的更好方法或知道如何保留查询字符串,即使使用 skipLocationChange 也会救我!

先感谢您。

听起来您应该将queryParamsHandling添加为“合并”或“保留”(取决于您的要求),例如

this.router.navigate(['categoria-listagem'], {
  skipLocationChange: true,
  queryParams: { page: 1, order: 'novidades' },  
  queryParamsHandling: "merge"
});

这应该将您的新查询参数添加到 URL 中的任何已有参数中。

此外,您可能需要再次删除skipLocationChange ,具体取决于您需要的功能。

暂无
暂无

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

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