I have the following route configuration:
const ROUTES = [
{
path: '',
component: ContainerComponent,
children: [
{ path: 'home', component: HomePageComponent }
],
canActivate: [UserConnectedGuard]
}
]
and the following effect:
@Effect()
loadProtectedData = this._dataPersistence.navigation(HomePageComponent, {
run: (route: ActivatedRouteSnapshot, state: AppState) => {
return this._backend.getProtectedData().pipe(
map((data) => ({
type: 'DATA_LOADED',
payload: data
}))
);
},
onError: (route: ActivatedRouteSnapshot, error) => {}
});
When navigating to /home
, the effect loadProtectedData
is called while the UserConnectedGuard
has not yet been resolved. Is that the expected behavior or do I miss something? Does anybody have an idea about the ideal architecture to solve that kind of dependency?
BTW, great work so far! Thanks guys.
DataPersistence.navigation
relies on the NgRx router integration. The integration dispatches the navigation event before the preactivation phase (Guards and Resolvers) executes, and that's why you are seeing the issue.
Could you submit an issue to https://github.com/ngrx/platform? I'll fix it in the NgRx repo.
Since the problem is caused by NgRx, I'm closing this issue.
Just ran into this issue. I searched ngrx bugs bug couldn't find an entry there, so I opened one up using the information in this thread.
https://github.com/ngrx/platform/issues/975
Thanks, :)
For anyone who happens to find this issue via Google (like me) the solution to stop this from happening is to update your StoreRouterConnectingModule
as follows:
StoreRouterConnectingModule.forRoot({
navigationActionTiming: NavigationActionTiming.PostActivation
})
This ensures that the ROUTER_NAVIGATION
actions that Nx looks for are only dispatched after guards have resolved.
This could also be done at the Nx level by instead listening for the ROUTER_NAVIGATED
action instead of ROUTER_NAVIGATION
but this might be a breaking change for some.
Most helpful comment
DataPersistence.navigation
relies on the NgRx router integration. The integration dispatches the navigation event before the preactivation phase (Guards and Resolvers) executes, and that's why you are seeing the issue.Could you submit an issue to https://github.com/ngrx/platform? I'll fix it in the NgRx repo.
Since the problem is caused by NgRx, I'm closing this issue.