I don't know if this helps in your situation, but Sammy.js, a popular hash routing library, has a before handler. I used it in my application to write a previously available hash, and if it is a hash, I want them not to go, returns false, will keep them on this page. You still need to rewrite the url to display the previous page, but it seems to work.
See my answer in this other section for more details.
Grinn source share