Angular 2 final - change route parameter to URL programmatically

Suppose I actually have a results page ...

http: // server / results; dateFrom = 03-11-2016; page = 1

I would like to load page 2 as the results page, but I need to set the URL string in the browser http: // server / results; dateFrom = 11-11-2016; page = 2 in case someone decides to mark it.

so how to programmatically change the URL parameter in the address bar of a web browser?

ty!

+5
source share
1 answer

You can do this with this code:

import { Router } from '@angular/router'; ... constructor(private router: Router) {} changeRoute () { this.router.navigate(['/results', { dateFrom: this.dateFrom, page: this.page }]); } ... 

Take a look at the stackblitz demo .


See the router API for more information . navigate .

+14
source

Source: https://habr.com/ru/post/1259236/


All Articles