Always treat Router as the source of truth
When we use Ngrx, we can see that we will use a "StoreRouterConnectingModule" from the example app.
What it does, is that, it connects router state to store,
It will set up the router in such a way that right after the URL gets parsed and the future router state gets created, the router will dispatch a RouterAction
Check the post.
Code example:
class TalksEffects { @Effect() navigateToTalks = this.actions.ofType(ROUTER_NAVIGATION). map(firstSegment). filter(s => s.routeConfig.path === "talks"). switchMap((r: ActivatedRouteSnapshot) => { const filters = createFilters(r.params); return this.backend.findTalks(filters)
.map(resp => ({type: 'TALKS_UPDATED', payload: {...resp, filters}})); }).catch(e => { console.log('Network error', e); return of(); }); }
We can listen for "ROUTER_NAVATION" event, filter though the path, get the activated route snapshot, then snyc Router URL with BE.