vue-router子路由默认视图不显示

  1. 路由结构

    {
      path: '/my',
      name: 'my',
      component: require('./components/my.vue'),
      children:[
        {
          path: '/',
          name: 'cr',
          component: require('./common/vue/table.vue'),
        },
        {
          path: 'dt',
          name: 'dt',
          component: require('./common/vue/table.vue'),
        }
      ]
    }

2.视图结构

一级路由
          <li><router-link :to="{name:'home'}" tag="a">待支付订单</router-link></li>
          <li><router-link :to="{name:'all'}" tag="a">所有订单</router-link></li>
          <li><router-link :to="{name:'my'}" tag="a">我的债权</router-link></li>
          <li><router-link :to="{name:'apply'}" tag="a">申请债权</router-link></li>
二级路由
        <span style="margin-left: 30px"><router-link :to="{name:'cr'}">债权方</router-link></span>
        <span><router-link :to="{name:'dt'}">债务方</router-link></span>

3.警告提示

[vue-router] Named Route 'my' has a default child route.
          When navigating to this named route (:to="{name: 'my'"), the default child route will not be rendered.
          Remove the name from this route and use the name of the default child route for named links instead.

4.最后出现了子路由的默认视图不显示,但是也没有报错,想问下这到底是哪有问题

阅读 16.4k
3 个回答

要有默认子路由,那父路由的名字name得去掉

path: '/' 的路由是默认子路由,它不能有name属性。要么删掉这个子路由的name属性,要么设置它的path 不为‘/’

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