jdoe1010
jdoe1010

Reputation: 103

Angular 6 - Display variable on URL

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?

Upvotes: 0

Views: 713

Answers (1)

JeRivals
JeRivals

Reputation: 264

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']"

Upvotes: 1

Related Questions