Jawad Farooqi
Jawad Farooqi

Reputation: 345

Angular 7: Extract a certain route name from the current route

For instance if this Route is activated:

localhost/abc/xyz/:id/main

I want to know what is in place of main. Available options are 'main', 'feed', 'operations', 'associated', 'setting'.

it can be:

localhost/abc/xyz/:id/main
localhost/abc/xyz/:id/feed
localhost/abc/xyz/:id/operations
localhost/abc/xyz/:id/associated
localhost/abc/xyz/:id/setting

so whatever is written in the url at the last entry i want to capture that and use it in something.

Please mention the code to achieve this.

Thank you in Advance

Upvotes: 2

Views: 35

Answers (1)

Stanley De Boer
Stanley De Boer

Reputation: 5241

You can get the path parts with something like this: var segments = window.location.pathname.split('/');

And then you are looking for the last one in the list: segments[segments.length - 1]

Upvotes: 1

Related Questions