美文网首页
Vue-router路由嵌套地址改变不跳转记录

Vue-router路由嵌套地址改变不跳转记录

作者: 头大如牛 | 来源:发表于2020-02-26 09:41 被阅读0次

    干了一个很蠢的事,在使用ElementUI中的el-menu组件时,需要读取路由并跳转,发现嵌套路由不加载组件的问题,例如

    import Vue from 'vue'
    import VueRouter from 'vue-router'
    import Home from '../views/Home.vue'
    import Testa from '../views/Test2.vue'
    import Testb from '../views/Test3.vue'
    import Testc from '../views/Test4.vue'
    
    
    Vue.use(VueRouter)
    
    
    const routes = [
      {
        path: '/',
        name: 'Home',
        component: Home,
      },
      {
        path: '/home',
        name: 'Home',
        component: Home
      },
      {
        path: '/about',
        name: 'About',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
      },
      {
        path: '/test',
        name: 'test',
        component: () => import('../views/Test1.vue'),
        children:[
          {path: '/test/testa', name: 'testa',component: Testa},
          {path: '/test/testb', name: 'testb',component: Testb},
          {path: '/test/testc', name: 'testc',component: Testc},
        ]
      }
    ]
    
    const router = new VueRouter({
      routes
    })
    
    export default router
    

    组件正确读取$router中的参数,并且router属性也是打开的,会正常跳转url,但是没有加载组件,发现是我没有在Test1组件中,给出路由出口<router-view/>,由此 问题解决,这可真蠢,记录一下

    相关文章

      网友评论

          本文标题:Vue-router路由嵌套地址改变不跳转记录

          本文链接:https://www.haomeiwen.com/subject/xbnpchtx.html