Imagine we have the following two routes:
viewRoute = {
name: "View Route",
pattern: "/route/view"
}
editRoute = {
name: "Edit Route",
pattern: "/route/edit",
beforeExit: (fromState, toState, routerStore) => {
if (/* route change was triggered by browser button */) {
if (confirm("Do you want to discard changes?") {
return toState;
}
else {
return fromState;
}
}
}
}
If the user redirects from "edit" to "view" route by clicking "cancel" or "save" buttons, I don't want to show the discard-confirm dialog. But if they use the browser buttons, I do.
How can I determine within a route transition hook whether that route change was triggered by a browser button? Or alternatively, by a direct call to routerStore.goTo()?