Vue
Vue

How to use dynamic file import in vue router, and whats the benefit of using child routes ?

December 3, 2025

Vue Router code splitting uses dynamic import() on route components, creating separate chunks loaded only when routes activate, slashing the initial bundle by 60-80%.​
Vue Router supports () => import() to lazy-load components only when needed, reducing initial bundle size and improving performance.

Child routes let you group related pages under a shared layout, avoid duplicate UI code, and keep routes structured and scalable.They also improve loading speed since only the child view changes inside the parent layout.

Code

import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(),
  routes: [
    {
      path: '/dashboard',
      component: () => import('@/layouts/DashboardLayout.vue'),
      children: [
        { path: '', component: () => import('@/views/Dashboard.vue') },
        { path: 'reports', component: () => import('@/views/Reports.vue') }
      ]
    },
    { path: '/', component: () => import('@/views/Home.vue') }
  ]
})
Hire Now!

Need Help with Vue Development ?

Ready to leverage the power of conversational AI? Start your project with Zignuts expert AI developers.
bg-image
download-image
Company Deck
PDF, 3MB
© 2026 Zignuts Technolab. All Rights Reserved.
branch imagesbranch imagesbranch imagesbranch imagesbranch imagesbranch images