Vue--动态路由

router.addRouter的基础用法
静态路由
const routes = [
    {
        path: '/',
        name: 'Login',
        component: () => import(/* webpackChunkName: "about" */ '@/views/Login.vue')
    },
    {
        path: '/index',
        name: 'index',
        meta: { title: '首页', noCache: true },
        component: () => import(/* webpackChunkName: "about" */ '@/views/index.vue'),
        children:[]
        // children: [{
        //     path: '/test',
        //     name: 'test',
        //     component: () => import('../views/test.vue')
        // }
        // ]
    }
]
动态路由
const routeObj = {
    path: 'index/test', // 这里要把父路由的路径也带上
    name: 'test',
    meta: { title: '测试路由test', noCache: true },
    component: () =>
    import('../test/test.vue'),
}
//添加子路由只需把addRoute第一个参数填写父级路由的name
this.$router.addRoute('index', routeObj)
posted @ 2022-10-28 19:42  蒜泥捣莓  阅读(33)  评论(0编辑  收藏  举报