I need to prevent router to be navigated to another page (which is done by changing the hash) if some changes are made. Tried with HashChanger but it just fires \'hashChange\' e
Instead of stopping the router entirely, navigation can be prevented by event.preventDefault()
within the navigate event handler.
<App xmlns="sap.m" navigate=".onNavigate">
onNavigate: function(event) {
if (/* pending changes? */) {
event.preventDefault();
const { isBack, isBackToPage, isBackToTop } = event.getParameters();
if (isBack || isBackToPage || isBackToTop) {
window.history.go(1);
} else {
window.history.go(-1);
}
this.informUser("There are still pending changes.");
}
}
Demo: https://embed.plnkr.co/wp6yes
There is a stop function on the router https://sapui5.hana.ondemand.com/#/api/sap.ui.core.routing.Router/methods/stop
if you call it, the router will stop listening to hashchanges.
There is also function isStopped(). To (re-)activate the router, call initialize(...).