Nested routes and layouts
A settings area has several pages that share one sidebar. Repeating the sidebar in every page is wasteful, so Vue Router lets a route nest its children inside a parent.
const routes = [
{
path: '/settings',
component: SettingsLayout,
children: [
{ path: 'profile', component: Profile },
{ path: 'billing', component: Billing },
],
},
];
The parent route renders once and stays mounted while its children change. Its
component holds a second <RouterView />, and that is where the matched child
appears:
<!-- SettingsLayout.vue -->
<template>
<aside>Settings</aside>
<RouterView />
</template>
A child path without a leading slash is relative to its parent, so the
children above match /settings/profile and /settings/billing. The parent's
path is absolute; the child's is not.
Nested routes are how you build layouts: the parent owns the chrome that should
persist, and the child owns the content that swaps. You can nest further, and
each level renders into the <RouterView /> of the level above it.
You are about to answer a short quiz on nested routes and layouts.