webpack+vue2.0+router 嵌套路由报错?

完整代码地址:https://github.com/tuihou1233...

想要访问的路由地址:
访问 http://localhost:8081/#/index...

clipboard.png

app.vue

<template>
  <div id="app">
    <h3>我是app.vue</h3>
    <keep-alive>
      <router-view></router-view>
    </keep-alive>
  </div>
</template>

路由配置:
router.js

/* 设置整个APP的路由*/

import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)

import Index from '../views/index.vue'
import Rage from '../views/rage.vue'

const router=new VueRouter({
routes:[{
path:'/index',
component:Index,
children:[
{
path:'rage',
component:Rage
}
]
},{
path:"*",redirect:'/index/rage'
}]
})

export default router

报错的关键是在这个页面出现的:index.vue

<template>
    <div>
       <h3>我是index页面</h3>
    </div>
    <!--打开下面注释后,页面报错-->
    <!--<div>-->
        <!--<keep-alive>-->
            <!--<router-view></router-view>-->
        <!--</keep-alive>-->
    <!--</div>-->
</template>

rage.vue

<template>
    <div>
       <h3>我是rage页面</h3>
    </div>
</template>
阅读 3.1k
2 个回答

首先,要明白,template下面只能有一个父元素
去掉注释,template下面就有两个平级的元素(两个父元素)

template 下面只能存在一个父级元素标签

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题