Listen for changes in the hash part of the URL:
const id = window.location.hash.slice(1); // get the hash code from the address bar of browser
window.addEventListener('hashchange', (id) => {...});
Listen for when a page has loaded:
window.addEventListener('load', () => {...});