Named routes
See original GitHub issueOh hi there! 😄
I’m a laravel (php) developer and new to angular …
I read the docs about routes and one thing i really missed is named routes!
In laravel we can give a name to each route and get full path of the route with route
helper function in views
If we change the path for the route still the correct path shows in views, because the route name refers to the route path!
Have we something like that in angular? and if no please add this feature!
As the alternative solution i was thinking about write a custom route service and Inject it to all components but it seems to be a dirty solution, isn’t it? 😃
Thanks!
Issue Analytics
- State:
- Created 4 years ago
- Comments:16 (7 by maintainers)
Top Results From Across the Web
Navigate with named routes - Flutter documentation
The solution is to define a named route, and use the named route for navigation. To work with named routes, use the Navigator....
Read more >Named Routes - Vue Router
Named Routes # · No hardcoded URLs · Automatic encoding/decoding of params · Prevents you from having a typo in the url ·...
Read more >Flutter - Named Routes - GeeksforGeeks
Note: In Flutter, screens and pages are called routes. In this article, we will explore the process of navigating through two named routes....
Read more >Routing - Laravel - The PHP Framework For Web Artisans
Basic Routing. Redirect Routes; View Routes; The Route List · Route Parameters. Required Parameters; Optional Parameters · Named Routes · Route Groups. Middleware ......
Read more >What are Named Routes in Laravel? - Tutorialspoint
Named routes are routes with names. A name is given to the route defined and the name later can be used in case...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This would be incompatible with lazy loading as determining the route for a given name would require the module to be loaded already.
As for doing this within a module, you can add a
data: { name: string }
kind of property to your routes and create a service as you mentioned which does this (in fact, you could even build a library out of this). You can inject theROUTES
token (or useRouter#config
) to get the routes configuration in which you find the data block. I’m not seeing anything dirty about this since this is essentially the same thing a framework-side implementation would likely be doing (apart from maybe not using thedata
field, which is a minor detail).(Building this as a library actually sounds kind of nice, as you could do things like also create a pipe for syntax like
[routerLink]="'users.profile' | route: [user.id]"
and what not.)You should just make use of the hierarchy the Angular router gives you:
Now when the user uses
[routerLink]="'hero.action1' | route: hero.id"
, you walk through the routes to figure out the correct URL.An interesting question is if and whether this should allow “skips” in between the tree without a route name set. I’d say yes, as otherwise the usefulness is extremely limited, but this comes down to a design decision in the library