question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Oh 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:closed
  • Created 4 years ago
  • Comments:16 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
Airbladercommented, Apr 14, 2019

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 the ROUTES token (or use Router#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 the data 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.)

1reaction
Airbladercommented, Apr 17, 2019

You should just make use of the hierarchy the Angular router gives you:

const routes: Routes = [
    {
        path: "hero/:id",
        data: { name: "hero" },
        children: [
            {
                path: "action1",
                data: { name: "action1" },
                component: HeroAction1Component,
            },
            {
                path: "action2",
                data: { name: "action2" },
                component: HeroAction2Component,
            },

        ],
    },
];

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found