-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
Angular 5 - "Error: Cannot activate an already activated outlet" when named outlets are used in children #20694
Comments
…vateWith Instead of throwing an error, we are now able to deactivate the outlet before activating it again with a new route. This makes routing configuration more flexible when we have named outlets we want to re-use on different routes with nested child routes Closes angular#20694
I submitted the PR above which enables the use case described in the issue, without throwing an error. Cheers |
…vateWith Instead of throwing an error, we are now able to deactivate the outlet before activating it again with a new route. This makes routing configuration more flexible when we have named outlets we want to re-use on different routes with nested child routes Closes angular#20694
We've adopted angular at my place of work, and we're relying on this technique for routing because we don't want to embed router-outlet information into the url. Until this works we'll have to rely on a fork of @angular/router that has the fix in the pull request in it to keep moving forward. I guess it's a more involved way of +1'ing, but I just want it clear that there are others that need this fix too. |
I've got the same error, applying the suggested fix made it only worse (for me). I think throwing the error is still the correct way. |
…vateWith Instead of throwing an error, we are now able to deactivate the outlet before activating it again with a new route. This makes routing configuration more flexible when we have named outlets we want to re-use on different routes with nested child routes Closes angular#20694
You need to change a little bit the routes. One of the 2 child routes should not be named. And of course the IndexComponent should also have two outlets one named and one without name.
|
I applied the suggested fix and it fixed the issue for me. I'm not sure what the implications are though. I hope the Angular team accept the PR or at least let us know what their recommended workaround/fix is. |
We have also same problem and fix above helps, what are the plans for merge? |
I have the same problem but I strongly disagree with replacing the error with a call to A better fix would be changing the router to not call |
Just to be sure does the solution not work without earlier version of Node? |
...Ah, Do not add |
Have the configs similar to the follows, it works for me. No errors even without fixes. app-routing.ts
dashboard-routing.ts
acount-routing.ts
|
solved this issue? |
Same problem here … |
found a working workaround here: #20712 (comment) |
@nofear87 FYI for me that fix only fixes the error when routing to the page after the app is loaded. While it does work It does not get rid of the error for a direct route to the child route. Are you seeing that as well? Any update on a fix for this issue? |
This guy's got a working answer: https://stackoverflow.com/a/55742986/3000466.
|
Amazing that this helped me get what I wanted but I still have a bad design... welp to pre-day patches. |
Hello, refer to this video for understanding how route config works and where to put the router outlet. |
This is sort of a hack and should not be used. Please refer to my answer for resolving this. |
@aakashgarg19 But it seems to not mention how to work with multiple outlet |
My routing tree already looks like that - but with additional levels of lazy-loading (and the tree configuration is split into separate files at the lazy-load boundaries). And I'm still getting this error with no named outlets and nested primary outlets. |
Hi, struggled a while with this myself, but found a way to structure my routes so that the issue no longer occurred, have posted an example of my routes below, hope this can help some of you.
|
The suggestion above finally solved it for me. It seems like the angular router doesn't deactivate named router outlets if it can't first deactivate an un-named one, even if the un-named router-outlet doesn't exist in the template. As long as it is present in the router configuration, it's gonna work. Ex: This doesn't work:
But this does:
|
Finally! Adding a primary (unnamed), empty router-outlet to my template completely fixed it. Thank you |
Having the same problem and trying not to make our routing messier and having to embed multiple outlet state into our urls. The idea in the PR above works for us (Angular 9.0.6). Any chance there could be movement on this so we don't have to track our own fork for a one liner? |
This and deactivating the router-outlets 'manually' on an ActivationStart as suggested in this issue fixed it for me. I have one router-outlet in a BottomSheet, which in my running solution is my primary outlet (unnamed). I'm running angular in v9.0.7, would be nice to know this fixed some day ;) |
This is sort of a hack and should not be used. Manual deactivation should not be done. If your router config is proper you will not face this issue and will not need this. Please refer to my answer for resolving this. Basically nested router outlet you can search if still there are some doubts. |
Confirmed in v10; Stackblitz repro: https://stackblitz.com/edit/angular-ivy-2xhhaz?file=src%2Fapp%2Fapp.module.ts |
During route activation, a componentless route will not have a context created for it, but the logic continues to recurse so that children are still activated. This can be seen here: https://github.com/angular/angular/blob/362f45c4bf1bb49a90b014d2053f4c4474d132c0/packages/router/src/operators/activate_routes.ts#L151-L158 The deactivation logic does not currently account for componentless routes. This is particularly a problem when named outlets are children of those routes because their outlets will never get a deactivation event. It's not a problem for primary outlets because some primary outlet parent will still get a deactivation on a changed route. This commit adjusts the deactivation logic so that if a context cannot be retrieved for a given route (because it is componentless), we continue to recurse and deactivate the children using the same `parentContexts` in the same way that activation does. Fixes angular#20694
During route activation, a componentless route will not have a context created for it, but the logic continues to recurse so that children are still activated. This can be seen here: https://github.com/angular/angular/blob/362f45c4bf1bb49a90b014d2053f4c4474d132c0/packages/router/src/operators/activate_routes.ts#L151-L158 The current deactivation logic does not currently account for componentless routes. This commit adjusts the deactivation logic so that if a context cannot be retrieved for a given route (because it is componentless), we continue to recurse and deactivate the children using the same `parentContexts` in the same way that activation does. Fixes angular#20694
During route activation, a componentless route will not have a context created for it, but the logic continues to recurse so that children are still activated. This can be seen here: https://github.com/angular/angular/blob/362f45c4bf1bb49a90b014d2053f4c4474d132c0/packages/router/src/operators/activate_routes.ts#L151-L158 The current deactivation logic does not currently account for componentless routes. This commit adjusts the deactivation logic so that if a context cannot be retrieved for a given route (because it is componentless), we continue to recurse and deactivate the children using the same `parentContexts` in the same way that activation does. Fixes angular#20694
During route activation, a componentless route will not have a context created for it, but the logic continues to recurse so that children are still activated. This can be seen here: https://github.com/angular/angular/blob/362f45c4bf1bb49a90b014d2053f4c4474d132c0/packages/router/src/operators/activate_routes.ts#L151-L158 The current deactivation logic does not currently account for componentless routes. This commit adjusts the deactivation logic so that if a context cannot be retrieved for a given route (because it is componentless), we continue to recurse and deactivate the children using the same `parentContexts` in the same way that activation does. Fixes angular#20694
…40196) During route activation, a componentless route will not have a context created for it, but the logic continues to recurse so that children are still activated. This can be seen here: https://github.com/angular/angular/blob/362f45c4bf1bb49a90b014d2053f4c4474d132c0/packages/router/src/operators/activate_routes.ts#L151-L158 The current deactivation logic does not currently account for componentless routes. This commit adjusts the deactivation logic so that if a context cannot be retrieved for a given route (because it is componentless), we continue to recurse and deactivate the children using the same `parentContexts` in the same way that activation does. Fixes #20694 PR Close #40196
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
I'm submitting a...
Current behavior
As stated here on stackoverflow when you have a routing configuration like:
And you are navigating from
/home
to/about
using a link<a routerLink="['/about']">about</a>
it throws the following error:Expected behavior
The expected behavior would be that it navigates to
/about
and the router populates the named outlets with the new components (taking internally care of deactivation/activation of outlets).Minimal reproduction of the problem with instructions
Just a simple app, with routing a named outlets with the configuration above.
What is the motivation / use case for changing the behavior?
It's a show stopper.
Environment
The text was updated successfully, but these errors were encountered: