2

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

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

2 Comments

Yes, for the current case it would be a solution. However, I want to do the navigation programmatically. I have updated my question
You can use every element of route array as variable, but if you want something closer to your approach you can try: this.router.navigate(app/${foo}/article/edit/${id}); I updated answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.