不努力code 2023-07-27 19:15 采纳率: 60%
浏览 6

多个router-view嵌套问题

我在使用vue-router中。一个页面使用多个router-view。我要在tabbarProfile中在加路由,遇到了嵌套问题

import type { RouteRecordRaw } from 'vue-router'
const routes: RouteRecordRaw[] = [
  {
    path: '/',
    name: 'index',
    component: () => import('@/view/index/index.vue'),
  },
  {
    path: '/tabbar',
    name: 'tabbar',
    redirect: (_) => ({ name: 'tabbarHome' }),
    component: () => import('@/view/tabbar/index.vue'),
    children: [
      {
        path: '',
        name: 'tabbarHome',
        components: {
          tabbarHome: () => import('@/view/tabbar/home/index.vue'),
          tabbarProfile: () => import('@/view/tabbar/profile/index.vue'),
        },
      
      },
    ],
  },
]

export default routes


我希望可以样这样,但是不行

import type { RouteRecordRaw } from 'vue-router'
const routes: RouteRecordRaw[] = [
  {
    path: '/',
    name: 'index',
    component: () => import('@/view/index/index.vue'),
  },
  {
    path: '/tabbar',
    name: 'tabbar',
    redirect: (_) => ({ name: 'tabbarHome' }),
    component: () => import('@/view/tabbar/index.vue'),
    children: [
      {
        path: '',
        name: 'tabbarHome',
        components: {
          tabbarHome: () => import('@/view/tabbar/home/index.vue'),
          tabbarProfile: {
            path: '',
            component: () => import('@/view/tabbar/profile/index.vue'),
            children,[...]
          },
        },
      },
    ],
  },
]

export default routes


  • 写回答

2条回答 默认 最新

  • 不努力code 2023-07-27 19:27
    关注

    我之所以需要这样。是因为我的tabbar是个swiper。需要定义多个router-view

    评论

报告相同问题?

问题事件

  • 创建了问题 7月27日