Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nitayneeman/eb0d81ca721ddfc9978fe557ca8d8cc7 to your computer and use it in GitHub Desktop.
Save nitayneeman/eb0d81ca721ddfc9978fe557ca8d8cc7 to your computer and use it in GitHub Desktop.
window.addEventListener('hashchange', async () => {
// Extracts the new route
const route = window.location.hash.substr(1);
// Loads the module based on the route
const { myFunction } = await import(`./${route}.mjs`);
myFunction();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment