在 Angular2 中更新 URL 而不重新加载路由

Updating URL without reloading route in Angular2

我有一个 Angular 2 应用程序,它使用 URL 检索股票报价,例如 http://host/stocks?symbol=AAPL

在页面加载时,获取默认符号,url 反映了这一点。但是,如果我在页面的输入字段中输入一个符号,然后单击 "Get Quote" 按钮,将获取结果,但 url 仍然反映默认符号。如何在获取新符号后更新 url? 谢谢

也许你可以使用定位服务来改变url:

 /**
  * Changes the browsers URL to the normalized version of the given URL, and pushes a
 * new item onto the platform's history.
 */
 go(path: string, query: string = ''): void {
  this._platformStrategy.pushState(null, '', path, query);
 }