I used Vue-CLI 3 and told it that I want to use vue-router. It generates this type of Webpack import statement in the created routes.js.
// route level code-splitting
// this generates a separate chunk (about.[hash].js) for this route
// which is lazy-loaded when the route is visited.
component: () => import(/* webpackChunkName: "about" */ './views/About.vue')
I proceeded to create four views. Some views call components inside.
Home.vue (Home page and default route at '/')
About.vue
Contact.vue
Photos.vue
I have made About, Contact, and Photos asynchronous in routes.js
import Home from './views/Home.vue';
/* name = named routes */
export const routes = [
{
path: '/',
component: Home,
name: 'home'
},
{
path: '/photo/:id',
// component: Photo,
component: () => import(/* webpackChunkName: "Photo" */ './views/Photo.vue'),
name: 'photo'
},
{
path: '/about',
component: () => import(/* webpackChunkName: "About" */ './views/About.vue'),
// component: About,
name: 'about'
},
{
path: '/contact',
// component: Contact,
component: () => import(/* webpackChunkName: "Contact" */ './views/Contact.vue'),
name: 'contact'
},
{
/* Wildcard path to catch all other paths */
path: '*',
redirect: '/'
}
];
When I do a build, Vue CLI does create additional JS and CSS chunks (about.[hash].js, etc.). However, when I load the Home route, these other chunks are loaded according to Chrome's devtools, but there is also nothing in the response tab. Then, when I visit About, Contact, or Photo routes, the browser loads those chunks, but now there is now something in the response tab.
Is async working as intended?
Thanks.