'Angular2 with matrix url notation
Is the matrix url notation the "default" to creating urls with parameters or is better to use the "old" notation with ? and &. I didn't understand it on the angular.io documentation
localhost:3000/heroes;id=15;foo=foo
or
localhost:3000/heroes?id=15&foo=foo
Solution 1:[1]
For matrix parameters you can also subscribe to params instead of peeling them out of url.
this.paramSubscription = this.activeRoute.params.subscribe(params => {
const bar = params['bar'];
const baz = params['baz'];
});
Solution 2:[2]
Both notations can be used but there is a restriction for the "old" notation. You can have only one question mark one question mark character in the URL.
With the matrix params, you can have different queries for different segments.
When is useful?
Add queries params for your auxiliaries router outlets.
For specials cases like one view with two components and each component has its own pagination information.
You want to keep that information if the user goes back to this view.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | dduft |
| Solution 2 | Lievno |
