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.

URL Matcher to allow service injection, to allow two routes with same path to be selected based on criteria.

See original GitHub issue

🚀 feature request

Relevant Package

This feature request is for @angular/router

Description

Currently we have 2 levels of authorisation in our app: Super admin and Organisation Admin. When those users login via /auth/login the are authenticated and then the logic redirects to the root /. On the route path (‘’), I have 2 child routes, both using an UrlMatcher instead of a path.

{
  path: '',
  children: [
    {
       matcher: SuperAdminMatcher
       loadChildren: <super admin module>
    },
    {
       matcher: OrgAdminMatcher
       loadChildren: <Org admin module>
    }
  ]

Those matcher functions require to know what user was logged in via the AuthService. However, other then looking in my LocalStorage and get my JWT, there is no way for me to access the AuthService because I can’t inject that service in the Matchers. So my matcher can never reject based on AuthState.

I ideally want to offer to paths: Superadmin: /organisation/list /organisation/ORG NAME/post/list <- super admin opening an Organisation

Org admin: /post/list /post/edit/<guid>

So unfortunately I have to use to different path names to make this work, and that makes the path unnecessary long, like `http://localhost:4200/superadmin/organisation/Bramble-Cay-College/post/list

Describe the solution you’d like

If you have a solution in mind, please describe it.

Allow for Injection of Providers in the Matcher. This way we can create a more advanced matcher. It is kinda like Resolve, however Resolve is currently happening after the Path or Url has been matched.

Describe alternatives you’ve considered

Have you considered any alternative solutions or workarounds?

The only real workaround I can find is using different path names, or using a wrapper component. However, I want each child to lazy load a Module, and I create a RootComponent, and load either the SuperAdminComponent or the OrgAdminComponent via *ngIf, it wouldn’t be lazy loaded.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:33
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

9reactions
krokofantcommented, Jan 27, 2020

Very valuable if you want to change the routed component based on feature toggles.

0reactions
angular-automatic-lock-bot[bot]commented, Jul 14, 2022

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tutorial: Creating custom route matches - Angular
In this tutorial, you'll build a custom route matcher using Angular's UrlMatcher . This matcher looks for a Twitter handle in the URL....
Read more >
Angular 6+ Dependency Injection & Async in UrlMatcher
It lets you control whether a route should be used at all even if its path or matcher match, allowing to skip the...
Read more >
Routing in ASP.NET Core - Microsoft Learn
Routing is responsible for matching incoming HTTP requests and dispatching those requests to the app's executable endpoints.
Read more >
Working with Angular 14 Router - Techiediaries
Route guards enables you to allow or disallow access to your specific application routes based on some criteria (for example if the user...
Read more >
Istio / Traffic Management
Istio's traffic routing rules let you easily control the flow of traffic and ... Istio match each given request to the virtual service...
Read more >

github_iconTop Related Medium Post

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