vue 路由嵌套(子路由跳转报错或者失效解决方法)

嵌套路由时,子路由懒加载有时会失效,最好定义引用好,再进行加载,示例结构:

{
    path: '/shopRech',
    redirect:'/shopRech/shopRechHome',
    component:{
      template:'<div> <router-view></router-view></div>'
    },
    meta: { title: '积分充值'},
    children:[
      {
        path: 'shopRechHome',
        name:'shopRechHome',
        component:home ,
        meta: { title: '积分充值'}
      },
      {
        path: 'rechargeInfo',
        name:'rechargeInfo',
        component:shopRechHome,
        meta: { title: '积分充值'}
      },
    ]
  },

如果是直接跳转,不是父页面>加载<router-view></router-view>,那么结构如上面例子所示。如果写入报错 You are using the runtime-only build of Vue where the template compiler is not available. Either pre-compile the templates into render functions, or use the compiler-included build.那么在你的项目配置项,以vue.cli3为例,在vue.config.js里面写入runtimeCompiler: true配置
如果 component:{template:'<div> <router-view></router-view></div>'},不起作用尝试 component: { render(c) {return c('router-view') }},在这里插入图片描述注意:子路由path不要写 “/” 。写入 / 会跳不到或者报错。子路由component引入,先定义再引入,懒加载component: () => import('@/views/commodityManagement/goodsRule/index.vue'),会失效。

  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值