vue3添加子路由

參考資料: https://www.w3cways.com/2404.html
Vue Router中router.addRoute添加子路由的用法
新版Vue Router中用router.addRoute來替代原有的router.addRoutes來動態(tài)添加路由、子路由

在添加子路由的時(shí)候

比如原現(xiàn)有路由

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')
        // }
                // ]
    }
]

想要在index下動態(tài)添加子路由test,特別要注意添加的子路由的path一定要把父路由的路徑也帶上

const routeObj = {
    path: 'index/test', // 這里要把父路由的路徑也帶上
    name: 'test',
    meta: { title: '測試路由test', noCache: true },
    component: () =>
        import('../test/test.vue'),
}
this.$router.addRoute('index', routeObj)
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容