嗯,我在问这个问题之前做了一些研究。我认为这很简单,因为这是一个常见的场景。
这是我的锚标签。
<a [routerLink]="['./product', 1]">Vitamins</a>当使用时,单击我通过将Id传递给Web API来获取数据。获取数据后,Url显示为http://localhost:4200/product/1。
在我的路由中,我将其配置为
{ path: 'product/:id', component: ProductComponent },我想将这个网址修改为http://localhost:4200/vitamins,这样更有意义。我该怎么做呢?
我找到的最接近的是这个,但这不是我要找的
发布于 2017-06-22 22:12:21
尝试使用Location对象。
import { Location } from '@angular/common';
constructor(public location: Location) {}当您想在不重定向或导航路由器对象的情况下更新窗口URL时,请放置以下内容:
this.location.go('vitamins');这应该在你的基本url后面写上'vitamins‘。
https://stackoverflow.com/questions/44701477
复制相似问题