Skip to content

Instantly share code, notes, and snippets.

@synga
Created February 16, 2018 13:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save synga/202ad48d34f4aca827d3e5c0bb75e676 to your computer and use it in GitHub Desktop.
Save synga/202ad48d34f4aca827d3e5c0bb75e676 to your computer and use it in GitHub Desktop.
Example of how to lazy load pages in VueJS, this'll result in a page per chunk.
// Lazy Loading a component
const HomePage = resolve => {
require.ensure(['./components/Home/HomePage.vue'], () => {
resolve(require('./components/Home/HomePage.vue'));
});
};
// Exported routes to be used in main.js
export const routes = [
{
path: '/home',
components: {
default: HomePage
}
},
{
path: '*',
redirect: '/'
}
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment