-
Notifications
You must be signed in to change notification settings - Fork 31
Fix - Router navigation cancel on error or rejected "before" hook #505
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
base: dev
Are you sure you want to change the base?
Changes from 1 commit
e9fffcb
cca9889
8a3d464
90a4a38
d160cb1
71cf790
c9c89f5
a22a385
d28ee76
46d9aad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -267,10 +267,22 @@ export const navigate = async function () { | |
|
|
||
| let beforeHookOutput | ||
| if (route.hooks.before) { | ||
| beforeHookOutput = await route.hooks.before.call(this.parent, route, previousRoute) | ||
| if (isString(beforeHookOutput)) { | ||
| try { | ||
| beforeHookOutput = await route.hooks.before.call(this.parent, route, previousRoute) | ||
| if (isString(beforeHookOutput)) { | ||
| currentRoute = previousRoute | ||
| to(beforeHookOutput) | ||
| return | ||
| } | ||
|
Comment on lines
+290
to
+294
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some changes to this portion have been made by me around the same time as your PR (see: https://github.com/lightning-js/blits/pull/502/files). We should make sure that we keep that functionality in tact There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Checked this, updated my dev branch with upstream dev branch and now it has all your changes plus the the additions to the router hooks |
||
| } catch (error) { | ||
| console.error('Error or Rejected Promise', error) | ||
|
|
||
| this[symbols.state].preventHashChangeNavigation = true | ||
| currentRoute = previousRoute | ||
| to(beforeHookOutput) | ||
| window.history.back() | ||
|
|
||
| navigatingBack = false | ||
| state.navigating = false | ||
| return | ||
| } | ||
| } | ||
|
|
||
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.
instead of adding an extra state variable (
preventHashChangeNavigation) to the router view, wouldn't it be more clean to keep this contained in the router logic itself?in that case we would just always call
Router.navigate.apply(this)and check a prevent has change variable in the router in thenavigatemethod