I'm implementing router for navigating in single-page application (something like Angular's ui-router
). Routing will be done by changing browser location's hash.
It should be impossible to navigate to an undeclared route. So if I've declared only #/foo
route, and currently I'm on #/foo
and trying to change hash to #/bar
, browser should revert hash to #/foo
.
However, after that #/bar
will remain in browser's history. The question is: how to completely prevent history changing on hash navigation?
I've tried
$(window).on('hashchange', function(event) {
event.preventDefault();
return false;
})
but it didn't work.