Artur Smolen
Artur Smolen

Reputation: 106

Angular routing with multiple parameters, and some in the middle

I have the following route:

app/:foo/article/edit/:id

I was hoping I could navigate to this route by doing something like the following:

this.router.navigate(['app/:foo/article/edit/:id', 1, 3]);

But that doesn't work and I couldn't find any navigation or URL generation function for this purpose.

Do I realy need to replace the parameters myself?

EDIT:

I want to navigate programmatically because this is not the only route I want to navigate to. This is all done in a Route Guard and depending on the requirement I want to navigate to a different route. In the following another route:

app/:foo/material/wareneingang/edit/:id

Upvotes: 2

Views: 3209

Answers (1)

Marcin Krysiak
Marcin Krysiak

Reputation: 347

Try this:

this.router.navigate(['/app', 1, 'article', 'edit' 3]);

You can replace number values with variables as well.

EDIT:

If you want something closer to your approach you can try:

this.router.navigate(`app/${foo}/article/edit/${id}`);

Hope it helped

Upvotes: 4

Related Questions