I have a regular angular 4 application and I use Router, ActivatedRoute.params.subscribe, [routerLink] etc. to navigate between pages and interpret URLs.
Now this leads to the fact that I have many "magic strings" flying around, because many different .ts-Files have url fragments. Of course, this works because they match, but it seems to be confused. Here is a random example:
<a [routerLink]="['/foo']">Home</a>
<a [routerLink]="['/foo/item', 1]">Item 1</a>
<a [routerLink]="['/foo/item', 2]">Item 2</a>
One of my ideas was to create a service that builds URLs for components and, therefore, knows about the structure of the URL. This is just one idea that I had, but I'm not so experienced with angular and maybe the “magic lines” are the way to go for some reason.
Is there a better way to keep the structure of the urls from your components?
source
share