Rakhat
Rakhat

Reputation: 4942

Angular 2 difference between route parameters style

If I navigate programmatically using Router's navigate method

this.router.navigate(['/articles', {id: 1}]); result url is /articles;page=1

and the second way

this.router.navigate(['/articles', id]); result url is /articles/1

In both variant I can get values via this.activatedRoute.params.forEach((params: Params) => {});

So what is the difference except style?

P.S. Found question related to differences between query params & matrix params

Upvotes: 1

Views: 1768

Answers (1)

Günter Zöchbauer
Günter Zöchbauer

Reputation: 658037

{id: 1} in ['/articles', {id: 1}] is an optional route parameters and added as matrix parameters to child routes and query parameters to the root route

['/articles', id] is a normal and required route parameter that replaces :id in the route path.

Upvotes: 3

Related Questions