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

router-plugin: RouterNavigation should be fired only when NavigationEnd is triggered #658

Closed
xmlking opened this issue Nov 12, 2018 · 3 comments
Milestone

Comments

@xmlking
Copy link
Contributor

xmlking commented Nov 12, 2018

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => https://github.com/ngxs/store/blob/master/CONTRIBUTING.md
[ ] Other... Please describe:

Current behavior

RouterNavigation event is fired every time a navigation is initiated. some times navigation action will be canceled due to AuthGuards.

    this.actions$
      .pipe(
        ofActionSuccessful(RouterNavigation),
        map((action: RouterNavigation) => action.routerState as any)
      )
      .subscribe(data => {
        console.log(data.breadcrumbs);
        this.pageTitle.setTitle(data.breadcrumbs);
        this.analytics.setPage(data.url);
      });

Expected behavior

we don't want to update title if Router event canceled. would be nice if you can configure router-plugin module only fire RouterNavigation when NavigationEnd event is fired. or expose more events e.g., RouterNavigationSuccess etc.

Minimal reproduction of the problem with instructions

What is the motivation / use case for changing the behavior?

Environment


Libs:
- @angular/core version: 7.0.3
- @ngxs/store version: 3.2.0


Browser:
- [ ] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: v11.1.0
- Platform:  Mac

Others:

@xmlking
Copy link
Contributor Author

xmlking commented Nov 12, 2018

may be this can be updated to fire RouterNavigationSuccess action
https://github.com/ngxs/store/blob/master/packages/router-plugin/src/router.state.ts#L93

  private setUpStateRollbackEvents(): void {
    this._router.events.subscribe(e => {
      if (e instanceof RoutesRecognized) {
        this.lastRoutesRecognized = e;
      } else if (e instanceof NavigationEnd) {
        this.dispatchRouterSuccess(e);
      } else if (e instanceof NavigationCancel) {
        this.dispatchRouterCancel(e);
      } else if (e instanceof NavigationError) {
        this.dispatchRouterError(e);
      }
    });
  }

@markwhitfeld
Copy link
Member

@xmlking This issue may have been fixed by PR #895 which has just been released in v3.4.3!
Could you test and confirm if this issue has been fixed or not?

@xmlking
Copy link
Contributor Author

xmlking commented Mar 14, 2019

👍 working as expected

@xmlking xmlking closed this as completed Mar 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants