01、index.ts代码如下:
//创建路由并暴露出去 import {createRouter, createWebHistory} from 'vue-router' import Home from '@/view/Home.vue' import About from '@/view/About.vue' import News from '@/view/News.vue' import Detail from '@/view/Detail.vue'const router = createRouter({history: createWebHistory(),routes: [{name: 'zhuye', path: '/home', component: Home},{name: 'guanyu', path: '/about', component: About},{name: 'xinwen', path: '/news', component: News,//子类的path不需要加斜杠 children: [{// 一定要使用namename: 'neirong',path: 'detail',component: Detail,props(route) {return route.query},},]},{path: '/',redirect: '/home'}] })export default router
02、效果如下: