懒惰地加载Vue的父组件和所有嵌套路线

问题描述 投票:4回答:1

我对嵌套路由的延迟加载有问题!

这是我的父母路线:

import ChildRoutes from "app/modules/child.route”;

routes: [
    {
        path: '/child',
        component: resolve => require(['app/modules/root'], resolve),
        children: ChildRoutes
    }
]

我的child.route.js

import ChildHome from …
import ChildContact from …

export default [
    {
        path: '',
        name: 'childHome',
        component: ChildHome
    },
    {
        path: 'about',
        name: 'childAbout',
        // doesn’t work
        component: resolve => require(['./components/about.vue'], resolve)
    },
    {
        path: 'contact',
        name: 'childContact',
        // this one doesn’t work as well
        component: ChildContact
    },
    ...
]

当然,第一个子路由(childHome)是自动工作的,但是之后,我得到的是空白页面,没有任何组件!如果我既不懒散地装载父母也不装载孩子,一切都会很好!

我在做什么错?

值得一提的是,我的项目使用vue 2.0vue-routervuex和SSR

lazy-loading vue.js vue-router vuex
1个回答
0
投票

父母路线

import ChildRoutes from "app/modules/child.route”;
routes: [
    ...ChildRoutes,
]

child.route.js

export default [ 
    {
        path: '/child',
        component: () => import ('@/app/modules/root'), <-- Just verify this path,
        children: ...
    }
]
© www.soinside.com 2019 - 2024. All rights reserved.