vue-router2.2.0 多层路由不起效果?

新手上路,请多包涵
  1. 在使用vue-router的时候发现有children设置,但是设置并没有达到网上看到的效果,请问是哪里代码错误。

clipboard.png

clipboard.png

clipboard.png

clipboard.png

我访问 http://localhost:8080/#/ 出现 Hello组件

但是我访问http://localhost:8080/#/test/a 却没有出现 Test组件的内容

clipboard.png

clipboard.png

阅读 2.8k
2 个回答

嵌套路由表达组件的嵌套关系,子路由a的父级并没有指定component,所以就不会有内容出现了。而且父级组件还必须包含<router-view>才行。例如:

{
    path: '/test',
    name: 'test',
    component: Test,
    children: [
        {
            path: '/a',
            name: 'a',
            component: A
        }
    ]
},

component Test:

<template>
    <div>
        <h1>this is component test</h1>
        <router-view></router-view>
    </div>
</template>

文档链接https://router.vuejs.org/zh-cn/essentials/nested-routes.html

新手上路,请多包涵

children: [

    {
        path: 'a',
        name: 'a',
        component: A
    }
]
子路由里的path不加/
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题