Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Router state to RouterNavigatedPayload #1509

Closed
sbkpilot1 opened this issue Jan 10, 2019 · 1 comment · Fixed by #1511
Closed

Add Router state to RouterNavigatedPayload #1509

sbkpilot1 opened this issue Jan 10, 2019 · 1 comment · Fixed by #1511

Comments

@sbkpilot1
Copy link

sbkpilot1 commented Jan 10, 2019

Describe any alternatives/workarounds you're currently using

I had written this code to simulate the navigated action with v6, I want to switch to using the Router Navigated action now that it is supported in v7 router-store. However, my action handler requires access to the router state to query data associated with the activated route.

      // Temp - to workaround https://github.com/ngrx/platform/issues/975
       const serializer = new NgrxRouterStateSerializer();

    this.router.events.pipe(
       filter(e => e instanceof NavigationEnd)
      ).subscribe((e: NavigationEnd) => {
        const snapshot = this.router.routerState.snapshot;
        const routesRecognized: RoutesRecognized = new RoutesRecognized(e.id, e.url, e.urlAfterRedirects, snapshot);
        const routerStateData = serializer.serialize(snapshot);
        const routerNavigationPayload: RouterNavigationPayload<RouterStateData> = {
          routerState: routerStateData,
          event: routesRecognized
        };

        this.store.dispatch({
          type: ROUTER_NAVIGATED,
          payload: routerNavigationPayload
        });
    });

Other information:

If accepted, I would be willing to submit a PR for this feature

[ ] Yes (Assistance is provided if you need help submitting a pull request)
[ ] No

@geo242
Copy link

geo242 commented Jan 18, 2019

Yes please!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants