0

I am trying to solve a problem here.

I need to display a variable on the URL of my Angular App like this:

If variable is for example test I want to display the URL as localhost:xxxx/test and if the variable is changed to something the URL should be localhost:xxxx/something . I have read the Angular documentation but I was unable to find a related section, it's always about parsing data from the URL not injecting data to it.

Can someone point me to the right direction?

3
  • You should re-read the documentation. Commented Sep 6, 2018 at 10:28
  • It's still unclear to me how this works. An actual example would be more helpful than row docs. Commented Sep 6, 2018 at 10:42
  • I understand, but I'm sorry, we're not here to teach you Angular basics. You should try it yourself, and if you encounter an issue, then you post a question here. Besides, the examples there are well explained, and they usually provide a stackblitz to let you test it. Commented Sep 6, 2018 at 10:44

1 Answer 1

1

You can add a dynamic parameter in your route definition, for example :

{ path: 'xxxx/:myVar', component: MyComponent }

and then you use the router to navigate into your component :

this.router.navigate(['/xxxx', 'test'])

or you use links into your template

<a href="" [routerLink]="['/xxxx', 'something']"
Sign up to request clarification or add additional context in comments.

Comments

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.