Search code examples
angularurlangular-router

Change angular router URL scheme


When I try to pass some parameters to my URL the angular router provides some URL schemes that I don't really like.

The URLS in this example look like this:

https://whatever.io/crisis-center;id=2;foo=foo

And I would like them to look like some 'conventional' URLs.

Something like: https://whatever.io/crisis-center?id=2&foo=foo

Is there a way to change the URL scheme for the Angular2^ router? If so, any advice or example on how to do it?


Solution

  • You can use query parameters when routing in angular

    this.router.navigate(['/crisis-center'], { queryParams: { id: 2, 'foo': 'foo' } });
    

    Your URL will look like this :

    http://localhost:4200/crisis-center'?id=2&foo=foo