You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was trying to use standalone components instead of modules based on the "Virtual NgModule mental model" described in #43784
I had a module which had just 1 component in it, and decided to replace that with the standalone component instead
On doing that, I noticed that the canLoad guard was not getting called.
And after some searching saw that in the loadComponent PR the last point mentioned was:
CanLoad guards do not apply to loadComponent. canActivate should be used instead, just like you would do if it were simply component instead.
I could not find this mentioned anywhere in the documentation, I checked:
I couldn't conclude if this is an expected behavior or a bug ...
And if expected is this something planned for standalone components or am I using standalone components for something it should not be using
Please provide a link to a minimal reproduction of the bug
The text was updated successfully, but these errors were encountered:
AbdealiLoKo
changed the title
Standalone components loadChildren() not calling canLoad/canMatch
Standalone components loadChildren() not calling canLoad
May 9, 2023
// Note that `canLoad` is only checked as a condition that prevents `loadChildren` and not
// `loadComponent`. `canLoad` guards only block loading of child routes by design. This
// happens as a consequence of needing to descend into children for route matching immediately
// while component loading is deferred until route activation. Because `canLoad` guards can
// have side effects, we cannot execute them here so we instead skip preloading altogether
// when present. Lastly, it remains to be decided whether `canLoad` should behave this way
// at all. Code splitting and lazy loading is separate from client-side authorization checks
// and should not be used as a security measure to prevent loading of code.
Which @angular/* package(s) are the source of the bug?
router
Is this a regression?
No
Description
Moving this SO question to the angular tracker.
I was trying to use standalone components instead of modules based on the "Virtual NgModule mental model" described in #43784
I had a module which had just 1 component in it, and decided to replace that with the standalone component instead
On doing that, I noticed that the
canLoad
guard was not getting called.And after some searching saw that in the
loadComponent
PR the last point mentioned was:I could not find this mentioned anywhere in the documentation, I checked:
I couldn't conclude if this is an expected behavior or a bug ...
And if expected is this something planned for standalone components or am I using standalone components for something it should not be using
Please provide a link to a minimal reproduction of the bug
https://stackblitz.com/edit/angular-standalone-component-canload
Please provide the exception or error you saw
No response
Please provide the environment you discovered this bug in (run
ng version
)Anything else?
NOTE: The original SO post says canMatch does not work either - but seemed to work for me.
Looks like canMatch() works but canLoad() does not work from my experiments in: https://stackblitz.com/edit/angular-standalone-component-canload
The text was updated successfully, but these errors were encountered: