如何像孩子一样设置vue-router嵌套路由

时间:2019-04-23 16:10:01

标签: vue.js vuejs2 vue-router

我正在尝试将作为常量导入的路由器放入主路由器的子级中

router / components / slider / index.js

const sliderRouter = {
    path: '/slider',
    name: 'Slider',
    meta: {
        title: 'Slider'
    },
    component: () => import('@/views/components/slider'),
}

export default sliderRouter



路由器/index.js

...

import authRouter from './modules/auth'
import sliderRouter from './modules/components/slider'

...

export default new Router({
    mode: 'history',
    linkActiveClass: "active selected",
    routes: [
        authRouter, // this work
        {
            path: '/admin',
            name: 'primary',
            meta: { requiresAuth: true },
            // remastered version
            component: loadView('MainLayout'),
            children: [
                sliderRouter,  /* make something like this */
                //recent routes
                {
                    path: '/home',
                    name: 'home',
                    // route level code-splitting
                    // this generates a separate chunk (about.[hash].js) for this route
                    // which is lazy-loaded when the route is visited.
                    // classic version:
                    component: () => import(/* webpackChunkName: "about" */ '../views/Home.vue')
                    // component: About
                }
            ]
        },

真的可以使滑条路由器以这种方式工作并从MainLayout继承(就像典型的子项一样),并且URL还是'/ admin / slider'吗?

1 个答案:

答案 0 :(得分:0)

我通过更改滑块中的路径来解决它

path: '/slider',

path: 'slider',

因为它的使用方式类似于子路由,所以在其名称前不需要斜杠