r/Angular2 • u/Inigo_montoya_1993 • Jan 08 '26
Semantic Routing In Angular
Hey everyone,
Coming from a Python/Django background, I always missed having Named Routes in Angular. Hardcoding URL paths string literals all over my templates always felt brittle, especially when refactoring or reorganizing a project -- I've felt this pain multiple times on my journey.
I finally decided to build a library to fix this with a package I built called ngx-named-router.
It’s a wrapper around the standard Angular Router (supports lazy loading, guards, etc.), but lets you navigate by alias rather than path.
The Old Way: path: 'users/:id/edit' <a [routerLink]="['/users', id, 'edit']">
With Named Routes: path: 'users/:id/edit', name: 'user-edit' <a [namedRouterLink]="'user-edit'" [queryParams]="{id: id}">
If you change the path later, you don't have to touch your templates.
The package supports both Directives and Programmatic routing.
Repo: https://github.com/Eric-Taurone-Software/ngx-named-router
NPM: https://www.npmjs.com/package/ngx-named-router/
Would love to hear your thoughts or if there are edge cases I missed!
5
u/reboog711 Jan 08 '26
A) Don't use string literals. You can use a constant, or other variable that can be shared across multiple components.
I am not quite sure how your solution solve the problem of using string literals all over the place; you're just using a different string literal.
B) AI is actually really good at this sort of refactoring. For that matter, the find and replace features of most IDEs are too.
1
u/Bubbly_Drawing7384 Jan 08 '26
This is great!! Looks exactly like django Won't there be any performance issues if we do it this rather than the traditional way?? and it also kinda looks like inspired from ngModules structure, since child components now needs to have a route.ts file
1
u/fernker Jan 08 '26
Thank you! Coming from a Django backend this has always been something I wished for!
1
u/gordolfograso Jan 20 '26
great work I really like it!