Code Monkey home page Code Monkey logo

Comments (1)

AnnCY1 avatar AnnCY1 commented on June 4, 2024

已经解决了,原来是作者为了方便添加路由,把路由从有children的 二层数组扁平化为一层数组了,导致子路由必须写完整路径才行,解决方案如下:
/src/routers/modules/dynamicRouter.ts 文件中把 相关代码替换掉

    // 3.添加动态路由(扁平化添加路由的方式会把子路由提升到和父路由同级,便无法在父路由中使用router-view标签来切换子路由 )
    // authStore.flatMenuListGet.forEach(item => {
    //   item.children && delete item.children
    //   if (item.component && typeof item.component == 'string') {
    //     item.component = modules['/src/views' + item.component + '.vue']
    //   }
    //   if (item.meta.isFull) {
    //     router.addRoute(item as unknown as RouteRecordRaw)
    //   } else {
    //     router.addRoute('layout', item as unknown as RouteRecordRaw)
    //   }
    // })

   // 3.添加动态路由
    const routeList = authStore.authMenuListGet.map(item => {
      const routeItem = {
        path: item.path,
        name: item.name,
        component: typeof item.component == 'string' ? modules['/src/views' + item.component + '.vue'] : null,
        meta: item.meta,
        children: [] as any
      }
      // 如果当前路由有子路由,则遍历子路由项并创建对应的子路由配置对象
      if (item.children && item.children.length > 0) {
        routeItem.children = item.children.map(child => ({
          path: child.path,
          name: child.name,
          component: typeof child.component == 'string' ? modules['/src/views' + child.component + '.vue'] : null,
          meta: child.meta
        }))
      }
      return routeItem
    })

    // 将路由配置数组动态添加到 Vue Router 中
    routeList.forEach((route: RouteRecordRaw) => {
      if (route.meta?.isFull) {
        router.addRoute(route as unknown as RouteRecordRaw)
      } else {
        router.addRoute('layout', route as unknown as RouteRecordRaw)
      }
    })

from geeker-admin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.