Search code examples
angularangular2-router3angular2-router

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


Solution

  • {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.