visionmedia / page.js

Micro client-side router inspired by the Express router
http://visionmedia.github.com/page.js
7.67k stars 687 forks source link

How to use dynamic import in page.js? #563

Open kresnasatya opened 4 years ago

kresnasatya commented 4 years ago

Hi, just curious do you have example how to implement dynamic import in page.js?

axelpale commented 3 years ago

I have implemented dynamic import with page.js and webpack v4 like below. It has worked well.

  page('/account', function () {
    import(
      /* webpackChunkName: "account-view" */
      '../components/Account'
    )
      .then(function (moduleWrap) {
        var accountView = moduleWrap.default;
        render(accountView);
      })
      .catch(importErrorHandler);
  });

For details, see Georap at GitHub (previously Tresdb) and search for router files under /client/js/routes/.