window.addEventListener('hashchange', router); code example
Example: javascript detect URL hash change
window.addEventListener("onhashchange", function(){
//url hash # has changed
});
window.addEventListener("onhashchange", function(){
//url hash # has changed
});