Zlatko
Zlatko

Reputation: 19569

How to push params to Url in Angular2 Router@3 without page reload

How can I push query params (page, limit) to url in angular, preferably without navigation.

I'm using the new, vladivostok router (npm @angular/router@3) and I have a table with paging. So when I click "next page" or change the number of items per page, I want to have that in the url.

I know I can programatically router.navigateByUrl('/users?page=3') or similar, but can I avoid navigating at all and just update the url? My services will reload the table and everything as needed. Or is that not the way to go?

Upvotes: 0

Views: 993

Answers (1)

Maximilian Riegler
Maximilian Riegler

Reputation: 23506

I think using window.history would do the trick:

window.history.pushState(null, "pagetitle", "users?page=4");

Upvotes: 1

Related Questions