路由懒加载
👉 等用户真正访问到某个路由页面时,才去加载对应的组件文件,而不是在应用一开始就把所有路由对应的组件都加载进来。
-
首屏优化 :如果你的项目很大,所有页面组件一次性打包,首屏加载速度会很慢。
-
分包加载 :只加载用户需要的页面,减少初始包体积。
-
体验更流畅 :用户点到新页面时才加载对应的资源,避免不必要的开销。
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
routes: [
{
path: '/',
redirect: '/dashboard',
component: () => **import('@/views/Layout/index.vue')** ,
children: [
{
path: 'article',
component: () => **import('@/views/Article/index.vue')**
},
{
path: 'dashboard',
component: () => **import('@/views/Dashboard/index.vue')**
}
]
},
{
path: '/login',
component: () => **import('@/views/Login/index.vue')**
}
]
})