路由表
来源:4-13 业务落地:创建结构路由表
Chen_SlovEnt
2023-05-07
Sunday老师,请问我在router\index.js中定义了如下函数,但我要怎么跟我的公开路由表合并呢,这个地方一直不知道怎么解决,求助中。
import { createRouter, createWebHashHistory } from 'vue-router’
import request from ‘@/utils/request’
async function getMyMenus() {
const res = await request({
url: ‘/menus/mymenus’,
method: ‘GET’,
})
const privateRoutes = res.menus.map(item => {
return {
path: item.path,
component: () => import(item.component),
meta: {
title: item.name,
id: item.id,
order_num: item.order_num
}
}
})
}
// // 私有路由表,从后台根据组权限获取
// const privateRoutes = [
//
// ]
// 公开路由表,无需从后台获取
const publicRoutes = [
{
path: ‘/login’,
component: () => import(’@/views/login/index’)
},
{
path: ‘/’,
component: () => import(’@/layout/index’),
children:[
{
path: ‘/profile’,
name: ‘profile’,
component: () => import(’@/views/profile/index’)
},
{
path: ‘/404’,
name: ‘404’,
component: () => import(’@/views/error-page/404’)
},
{
path: ‘/401’,
name: ‘401’,
component: () => import(’@/views/error-page/401’)
}
]
}
]
const router = createRouter({
history: createWebHashHistory(),
routes: […publicRoutes, …privateRoutes]
})
export default router
1回答
-
Sunday
2023-05-07
你好
我不太明白你的意思?你是想要这一段代码吗?
还是指的你带吗中的 getMyMenus? 他是干什么的?你期望如何合并?
162024-09-12