Utilizing webpack's code splitting feature, I have divided my application into multiple chunks to prevent the entire bundle from being downloaded at once when a user visits my website.
Some routes require large chunks that may take some time to download. Although this is acceptable, it can be confusing for users as they are unaware of the page loading progress when clicking on internal links. Therefore, I need to find a way to display a loading animation or indicator.
This is how my router is set up:
[
{
path: '/',
component: () => import(/* webpackChunkName: 'landing' */ './landing.vue'),
},
{
path: '/foo',
component: () => import(/* webpackChunkName: 'main' */ './foo.vue'),
},
{
path: '/bar',
component: () => import(/* webpackChunkName: 'main' */ './bar.vue'),
},
]
The Vue.js guide on Advanced Async Components demonstrates how to show a "loading" component while resolving the main component – exactly what I need. However, it also mentions:
Note that when used in vue-router, these properties are ignored since async components are resolved before route navigation occurs.
How can I implement this functionality in vue-router? If not achievable, lazily-loaded components would provide little benefit and result in a subpar user experience.