CanDeactivate not triggered when navigating from lazy loaded module component to root module
See original GitHub issueπ bug report
Affected Package
The issue is caused by package @angular/core, @angular/router.Is this a regression?
I do not know precisely. There was maybe a similar issue described here: #16868Description
When I put a CanDeactivate guard for the route of a component that is included inside a lazy loaded module and I try to navigate (for example with the back button) from this route to a route that is included in the root module (app.module.ts, for example the homepage) the CanDeactivate guard it is not called. This behaviour does not appear when navigating between two components (in which at least one is protected by the CanDeactivate) that are included in the same lazy-loaded module or are included in two different lazy-loaded modules.
π¬ Minimal Reproduction
https://stackblitz.com/edit/angular-issue-deactivate-guard-lazyload-module
π₯ Exception or Error
There are no exceptions or errors sadlyβ¦
π Your Environment
Angular Version:
Angular CLI: 7.2.2
Node: 10.15.0
OS: darwin x64
Angular: 7.2.1
... animations, cdk, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.12.2
@angular-devkit/build-angular 0.12.2
@angular-devkit/build-optimizer 0.12.2
@angular-devkit/build-webpack 0.12.2
@angular-devkit/core 7.2.2
@angular-devkit/schematics 7.2.2
@angular/cli 7.2.2
@angular/flex-layout 7.0.0-beta.23
@angular/http 7.2.2
@ngtools/webpack 7.2.2
@schematics/angular 7.2.2
@schematics/update 0.12.2
rxjs 6.3.3
typescript 3.2.2
webpack 4.28.4
Issue Analytics
- State:
- Created 5 years ago
- Reactions:15
- Comments:11 (1 by maintainers)
Top Results From Across the Web
canDeactivate() is not triggered on page navigation in Angular 8
Maybe the problem is that you r trying to deactivate a set of lazy loaded routes. Try to apply the CanDeactivateGuard to the...
Read more >CanDeactivate - Angular
Interface that a class can implement to be a guard deciding if a route can be deactivated. If all guards return true ,...
Read more >Resolving errors faced while implementing Lazy Loading with ...
HelloComponent may show as the root component even though it is not declared at the root route of AppComponent. Check that the imported...
Read more >In-app navigation: routing to views - Angular
The following command uses the Angular CLI to generate a basic Angular app with an app routing module, called AppRoutingModule , which is...
Read more >Understanding Angular Guards - codeburst
Modules in angular can be loaded all at once or be lazy loaded . ... which gets called whenever the user tries to...
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
When returning from lazy loaded module to root module.
Root Module
Lazy Loaded Feature Module
Child component having unsaved changes, trigger canDeacticvate but provider donβt have component reference
Child lazy loaded modules having single components with canDeactivate guard working fine in between component navigation
Working ( with canDeactivate guard )
Not working ( with canDeactivate guard )
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.