Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combination of redirecting under a primary route and route guarding a sibling route under a named outlet causes NG04013 #56519

Open
pfeileon opened this issue Jun 19, 2024 · 0 comments
Labels
area: router P4 A relatively minor issue that is not relevant to core functions
Milestone

Comments

@pfeileon
Copy link

pfeileon commented Jun 19, 2024

Which @angular/* package(s) are the source of the bug?

router

Is this a regression?

No

Description

On a route with two children with an empty path, one on a named outlet, the other with a child-redirect, the router seems to activate (and never deactivate?) the named outlet if a canMatch (or canActivate) guard returns false.

This causes the issue that after the initial navigation ("/items/:id") which successfully redirects ("items/:id/main"), every other parallel navigation throws the mentioned error.

If the guard returns true, everything works as expected.

Component/route hierarchy (I'm mixing component and route hierarchy for simplicity):

RootComponent
  primary outlet> someLazyRoutes => moreLazyRoutes => ListComponent => routesWithIssues
  named outlet> AsideComponent
export const routesWithIssues = [
  {
    path: ':id'
    children: [
      {
        path: '',
        loadComponent: () => ItemComponent,
        // initial redirection works,
        // navigating to or deep linking to other routes on the same level as "main" causes the error
        children: [
          // Removing this redirection route solves the issue (but has the side-effect that it doesn't redirect, obviously)
          {path: '', pathMatch: 'full', redirectTo: 'main'},
          ...otherTabbedChildRoutesIncludingMain
        ]
      },
      {
        path: '',
        outlet: 'aside',
        // If the guard returns true, no error occurrs.
        // (Strange sidenote: only defining `canActivate` breaks routing completely without an error message,
        // i.e. only the RootComponent is loaded)
        canMatch: [() => false],
        loadComponent: () => AsideComponent
      },
    ]
  }
] as Routes

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

Error: NG04013: Cannot activate an already activated outlet
    at RouterOutlet.activateWith (router.mjs:2552:19)
    at ActivateRoutes.activateRoutes (router.mjs:3146:40)
    at router.mjs:3097:18
    at Array.forEach (<anonymous>)
    at ActivateRoutes.activateChildRoutes (router.mjs:3096:29)
    at ActivateRoutes.activateRoutes (router.mjs:3113:22)
    at router.mjs:3097:18
    at Array.forEach (<anonymous>)
    at ActivateRoutes.activateChildRoutes (router.mjs:3096:29)
    at ActivateRoutes.activateRoutes (router.mjs:3117:22)

Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 17.3.8
Node: 20.14.0
Package Manager: npm 10.7.0
OS: linux x64

Angular: 17.3.10
... animations, cdk, common, compiler, compiler-cli, core, forms
... material, platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1703.8
@angular-devkit/build-angular   17.3.8
@angular-devkit/core            17.3.8
@angular-devkit/schematics      17.3.8
@angular/cli                    17.3.8
@schematics/angular             17.3.8
rxjs                            7.8.1
typescript                      5.3.3
zone.js                         0.14.6

Anything else?

I experimented with trying to deactivate the outlet imperatively, but it didn't work.

@ngbot ngbot bot added this to the needsTriage milestone Jun 19, 2024
@atscott atscott added the P4 A relatively minor issue that is not relevant to core functions label Jun 20, 2024
@ngbot ngbot bot modified the milestones: needsTriage, Backlog Jun 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: router P4 A relatively minor issue that is not relevant to core functions
Projects
None yet
Development

No branches or pull requests

3 participants