Search code examples
angularangular-routing

How to get all segments of route in angular


consider my url is like

#/desktop/admin/reconciliationconfig/nav/ledger/GMO-DDA-21819971/detail,

My question is how can I get all segments of the route in angular?

My expected result is

['desktop','admin','reconciliationconfig','nav','ledger','GMO-DDA-21819971','detail']

Note GMO-DDA-21819971 is a route param and will be changed dynamically


Solution

  • After getting the url from the router object, you can simply use the split function in the string

    this.router.url.split('/');