-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
fix(router-store): Handle navigation error, cancel/error action contain real previous state #1294
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, left some small remarks.
Also I'm not really at home (yet!) with router-store but I see that this.trigger !== RouterTrigger.STORE
is used everywhere, is this done for a reason?
I tested a few cases and my trigger was always NONE, so I would find it safer to write this.trigger === RouterTrigger.NONE
(after this change the tests were also passing). Not saying you have to change it, just wanting to understand it more.
@@ -119,7 +126,7 @@ describe('integration spec', () => { | |||
}); | |||
}); | |||
|
|||
it('should support rolling back if navigation gets canceled', (done: any) => { | |||
it('should support rolling back if navigation gets canceled (navigation initialized through roter)', (done: any) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo, roter -> router
@@ -301,7 +303,8 @@ export class StoreRouterConnectingModule { | |||
private store: Store<any>, | |||
private router: Router, | |||
private serializer: RouterStateSerializer<SerializedRouterStateSnapshot>, | |||
@Inject(ROUTER_CONFIG) private config: StoreRouterConfig | |||
@Inject(ROUTER_CONFIG) private config: StoreRouterConfig, | |||
private errorHandler: ErrorHandler |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move this to above the @Inject
parameter.
this.trigger = RouterTrigger.STORE; | ||
this.router.navigateByUrl(url); | ||
this.router.navigateByUrl(url).catch(e => { | ||
this.errorHandler.handleError(e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should write a test for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There already is, kind of, the "...if navigation errors (navigation initiated by store)"-test. I will enhance it to check the error handler is invoked correctly.
this.trigger = RouterTrigger.STORE; | ||
this.router.navigateByUrl(url); | ||
this.router.navigateByUrl(url).catch(e => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename e
to err
), | ||
}); | ||
} | ||
|
||
private dispatchRouterCancel(event: NavigationCancel): void { | ||
this.dispatchRouterAction(ROUTER_CANCEL, { | ||
routerState: this.routerState, | ||
routerState: this.routerState!, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason why this.routerState!
is used?
Is it to make clear the router state can't be null at this point?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's the only reason.
The RouterTrigger enum indicates who initiated the navigation and who is currently in control of it. If the navigation is initiated through the router, f.e. with |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the new behavior?
Fixes #1292, #1293
ROUTER_ERROR
/ROUTER_CANCEL
action now contain previos router and store stateDoes this PR introduce a breaking change?
Other information