Lazloman
Lazloman

Reputation: 1347

Updating URL without reloading route in Angular2

I have an Angular 2 app that retrieves stock quotes using a URL like http://host/stocks?symbol=AAPL

On page load, a default symbol is fetched and the url reflects this. But, if I enter a symbol the page's the input field and then click the "Get Quote" button, the results are fetched, but the url still reflects the default symbol. How do I get the url to update after fetching a new symbol? Thanks

Upvotes: 0

Views: 4008

Answers (1)

Julia Passynkova
Julia Passynkova

Reputation: 17859

May be you can use Location service to change 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);
 }

Upvotes: 3

Related Questions