publicRoutes、privateRoutes打印输出有问题

来源:8-10 业务落地:定义页面权限控制动作,实现页面权限受控-2

qq_艾诺_

2022-05-29

// src/router/routes/unauthorize-routes/index.ts
import Layout from '@/layout/index.vue'
import { RouteRecordRaw } from 'vue-router'

const routes: RouteRecordRaw[] = [
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login/index.vue')
  },
  {
    path: '/',
    component: Layout,
    redirect: '/profile',
    children: [
      {
        path: '/profile',
        name: 'profile',
        component: () => import('@/views/profile/index.vue'),
        meta: {
          title: 'profile',
          icon: 'user'
        }
      },
      {
        path: '/404',
        name: '404',
        component: () => import('@/views/error-page/404.vue')
      },
      {
        path: '/401',
        name: '401',
        component: () => import('@/views/error-page/401.vue')
      }
    ]
  }
]

export default routes

// src/router/routes/authorize-routes/index.ts
import { RouteRecordRaw } from 'vue-router'
import articleCreate from './article-create'
import article from './article'
import permissionList from './permission-list'
import userManage from './user-manage'
import roleList from './role-list'

const routes: RouteRecordRaw[] = [
  articleCreate,
  article,
  permissionList,
  userManage,
  roleList
]

export default routes


// /src/store/permission.ts
// 专门处理权限路由的模块
import publicRoutes from '@/router/routes/unauthorize-routes'
import privateRoutes from '@/router/routes/authorized-routes'
console.log(publicRoutes, privateRoutes)

export default {
  namespaced: true,
  state: {
    // 路由表:初始拥有静态路由权限
    routes: publicRoutes
  },
  ....
}

老师,permission.ts里打印出来的内容是这样的
图片描述
现在很是疑惑,目前也没有循环引用的问题。

写回答

2回答

qq_艾诺_

提问者

2022-05-29

已解决,main.ts里引入@/router和@/store顺序写反了,应该先引入router再引入store

0
0

qq_艾诺_

提问者

2022-05-29

我将permission模块从store/index下注释掉,然后去掉routerGuard对应的添加动态路由的代码,再在router/index.ts打印publicRoutes、privateRoutes,其中的component就不是undefined

0
0

基于Vue3新标准,打造后台综合解决方案

基于Vue3重写Vue-element-admin,打造后台前端综合解决方案

1941 学习 · 1687 问题

查看课程