欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

vue 嵌套路由 页面空白问题

程序员文章站 2022-06-13 08:00:36
...

vue 写嵌套路由时 页面打开空白

export default new Router({
  routes: [
    {
      path: '/',
      name: 'index',
      component: index
    },
    {
      path: '/index',
      name: 'index',
      component: Notice,
      children:[
        {
          path: '/notice',
          name: 'notice',
          component: Notice
        },

      ]
    },
    {
      path: '/science',
      name: 'science',
      component: Science
    }
  ]
})

按照正常逻辑这样写,感觉没问题,但是调试时出现了页面嵌套路由页面空白问题

解决方法:
把子路由的path路径的“/”去掉

export default new Router({
  routes: [
    {
      path: '/',
      name: 'index',
      component: index
    },
    {
      path: '/index',
      name: 'index',
      component: Notice,
      children:[
        {
          path: 'notice', //去掉“/”
          name: 'notice',
          component: Notice
        },

      ]
    },
    {
      path: '/science',
      name: 'science',
      component: Science
    }
  ]
})