Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ranwahle/de2739db8b58348419388c3fa8632cda to your computer and use it in GitHub Desktop.
Save ranwahle/de2739db8b58348419388c3fa8632cda to your computer and use it in GitHub Desktop.
onpopstate with navigating out confirmation
window.onpopstate = async (e) => {
const treeBuilder = module.Router.router.routingSnapshotTreeBuilder
const prevUrl = history.state && history.state.prev;
const currentRouteData = treeBuilder.buildRouteTree(prevUrl);
const router = module.Router.router
if (await router.canGoOn(window.location.pathname, null, currentRouteData && currentRouteData.deactivateGuard, prevUrl )) {
this.changeRoute(window.location.pathname)
} else {
history.back();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment