Complete the code to define a nested route in Vue Router.
const routes = [
{
path: '/parent',
component: ParentComponent,
children: [
{ path: '[1]', component: ChildComponent }
]
}
];The child route path should be relative without a leading slash, so 'child' is correct.
Complete the code to display child views inside the parent component.
<template>
<div>
<h1>Parent</h1>
[1]
</div>
</template>In Vue Router,
Fix the error in the nested route path to correctly match the child route.
const routes = [
{
path: '/dashboard',
component: Dashboard,
children: [
{ path: '[1]', component: Stats }
]
}
];Child route paths should be relative without a leading slash, so 'stats' is correct.
Complete the code to create a nested route with a default child view.
const routes = [
{
path: '/account',
component: Account,
children: [
{ path: '', component: Profile },
{ path: '[1]', component: Settings }
]
}
];An empty string path ('') defines the default child route, and 'settings' is the path for the other child.
Fill all three blanks to define nested routes and display child views inside the parent component.
<template>
<div>
<h2>Dashboard</h2>
[1]
</div>
</template>
<script setup>
import { createRouter, createWebHistory } from 'vue-router';
import Dashboard from './Dashboard.vue';
import Overview from './Overview.vue';
import Reports from './Reports.vue';
const routes = [
{
path: '/dashboard',
component: Dashboard,
children: [
{ path: '[2]', component: Overview },
{ path: '[3]', component: Reports }
]
}
];
const router = createRouter({
history: createWebHistory(),
routes
});
</script>The parent component uses <router-view> to show child views. Child paths are relative: 'overview' and 'reports'.