O'Reilly logo

The Majesty of Vue.js by Kostas Maniatis, Alex Kyriakidis

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Nested routes

Nested routes, are routes that live within other routes. Mapping nested routes to nested components is a common need, and it's also very simple with vue-router.

All we have to do is to declare "subRoutes" and use a nested <router-view>.

Nested routes

Project structure

Assuming we have the preceding structure, we can proceed to the following changes.

src/main.js:

router.map({
  '/': {
    component: require('./components/Hello.vue')
  },
  '/login': {
    component: require('./components/Login.vue')
  },
  '/stories': {
    component: require('./components/Stories.vue'),
    subRoutes: {
      '/famous': {
        component: require('./components/Famous.vue')
      },
    }
  },
})

As seen in the preceding ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required