Skip to content

Instantly share code, notes, and snippets.

@Danetag
Created December 4, 2018 23:01
Show Gist options
  • Select an option

  • Save Danetag/5cf68ece2084b81eed2b349d37b569a5 to your computer and use it in GitHub Desktop.

Select an option

Save Danetag/5cf68ece2084b81eed2b349d37b569a5 to your computer and use it in GitHub Desktop.
let currentView = null;
const pageLoaded = () => {
// "Routing"
const currentPage = document.querySelector("#content").firstElementChild;
switch (currentPage.id) {
case "home-page":
import(/* webpackChunkName: "homepage" */ "pages/homepage/homepage")
.then(currentViewImported)
.catch(error =>
console.log(
"An error occurred while loading the Hhmepage component",
error
)
);
break;
case "privacy-policy-page":
import(/* webpackChunkName: "privacy" */ "pages/privacy/privacy")
.then(currentViewImported)
.catch(error =>
console.log(
"An error occurred while loading privacy component",
error
)
);
break;
...
}
}
const currentViewImported = async ({ default: CurrentModule }) => {
if (currentView) currentView.dispose();
currentView = new CurrentModule();
await currentView.init();
currentView.show();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment