问题描述
我正在尝试为 SEO 自定义我的 url,我想显示传递给路由的参数,但隐藏路由定义的位置更改,如下所示:
{ path:'category/:id/:name',component:CatComponent}
我尝试过这样的事情:
this.router.navigate(['/browse/category'],{ queryParams:{ id: id,name: cat},skipLocationChange: true });
但这不起作用,请帮忙
解决方法
您可以尝试使用 angular 中的 replaceUrl
。它可以取代你当前的历史状态
参考https://angular.io/api/router/NavigationBehaviorOptions#replaceUrl
this.router.navigate(['/browse/category'],{
queryParams:{ id: id,name: cat},replaceUrl: true
});