I am trying to dispatch the router store navigation action relative to the component route. the trace log for routing shows that the relative path taken for navigation is the app-path instead of the component path.
return of(
new routerActions.Go({
path: ['./', payload.rootPath],
extras: { relativeTo: this.route },
}),
);
constructor(
private actions$: Actions,
private route: ActivatedRoute,
) {}
I am injecting the ActivatedRoute
in my effect module constructor which seems the issue here. How can I get the activated route outside of my component and pass it to the navigation action?
ActivatedRoute is specific to each routed component.
This gives you a couple options.
let route = this.router.routerState.root;
while (route.firstChild) {
route = route.firstChild;
}
return route.snapshot;
constructor(private store: Store<AppState>, private activatedRoute:ActivatedRoute) {}
doSomething() {
this.store.dispatch(new Action.YourAction({ id: actionId, route: activatedRoute });
}