Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Utility to render MicroFrontend
function renderMicroFrontend(pathname) {
const microFrontend = routes[pathname || window.location.hash];
const root = document.getElementById('microfrontend');
root.innerHTML = microFrontend ? new microFrontend().render(): new Home().render();
$(window).scrollTop(0);
}
$(window).bind( 'hashchange', function(e) { renderFrontend(window.location.hash); });
renderFrontend(window.location.hash);
utility routes.js (A map of the hash route to the Microfrontend class)
const routes = {
'#': Home,
'': Home,
'#home': Home,
'#cart': Cart,
'#checkout': Checkout,
'#product': Product,
'#contact': Contact,
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment