Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/components/RouterView.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,21 @@ export default () =>
state() {
return {
activeView: null,
preventHashChangeNavigation: false,
}
},
hooks: {
async ready() {
if (this.parent[symbols.routerHooks] && this.parent[symbols.routerHooks].init) {
await this.parent[symbols.routerHooks].init.apply(this.parent)
}
hashchangeHandler = () => Router.navigate.apply(this)
hashchangeHandler = () => {
if (this[symbols.state].preventHashChangeNavigation) {
this[symbols.state].preventHashChangeNavigation = false
return
}
Router.navigate.apply(this)
Copy link
Collaborator

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 the navigate method

}
Router.navigate.apply(this)
window.addEventListener('hashchange', hashchangeHandler)
},
Expand All @@ -58,4 +65,4 @@ export default () =>
}
},
},
})
})
18 changes: 15 additions & 3 deletions src/router/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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

Copy link
Author

Choose a reason for hiding this comment

The 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
}
}
Expand Down