no message
Former-commit-id: f3c11b2f64cc627044be20129050e193a8eec631 Former-commit-id: 49657d956a264020cda5ee3230870cf736197400 Former-commit-id: c3796afffe32e911c917133f2dc804cfe664acd7
This commit is contained in:
@@ -2,36 +2,8 @@ import Vue from 'vue'
|
|||||||
import VueRouter from 'vue-router'
|
import VueRouter from 'vue-router'
|
||||||
import Cookies from 'js-cookie'
|
import Cookies from 'js-cookie'
|
||||||
|
|
||||||
import pathPosix from 'path-posix'
|
|
||||||
import _get from 'lodash.get'
|
|
||||||
|
|
||||||
Vue.use(VueRouter)
|
Vue.use(VueRouter)
|
||||||
|
|
||||||
const routesMaker = ({publicPath, namePrefix, req}) => {
|
|
||||||
const win2posix = pathString => pathString.split('\\').join('/')
|
|
||||||
return req.keys().map(req).map(page => {
|
|
||||||
// 每个文件的路径 已经转换为 posix
|
|
||||||
const pagePath = pathPosix.dirname(win2posix(page.default.__file))
|
|
||||||
// 路由中使用的路径
|
|
||||||
const path = pagePath
|
|
||||||
.replace(win2posix(publicPath), '')
|
|
||||||
.replace(new RegExp('/page/', 'g'), '/')
|
|
||||||
const name = `${namePrefix}${path.split('/').join('-')}`
|
|
||||||
const route = {
|
|
||||||
path: `${path}${_get(page, 'router.pathSuffix', '')}`,
|
|
||||||
name,
|
|
||||||
...page.router,
|
|
||||||
meta: { requiresAuth: true },
|
|
||||||
component: page.default
|
|
||||||
}
|
|
||||||
console.log(JSON.stringify({
|
|
||||||
path: route.path,
|
|
||||||
name: route.name
|
|
||||||
}))
|
|
||||||
return route
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const routes = [
|
const routes = [
|
||||||
// 首页
|
// 首页
|
||||||
{
|
{
|
||||||
@@ -53,11 +25,9 @@ const routes = [
|
|||||||
meta: { requiresAuth: true },
|
meta: { requiresAuth: true },
|
||||||
redirect: { name: 'demo-plugins-index' },
|
redirect: { name: 'demo-plugins-index' },
|
||||||
component: resolve => { require(['@/components/core/MainLayout/index.vue'], resolve) },
|
component: resolve => { require(['@/components/core/MainLayout/index.vue'], resolve) },
|
||||||
children: routesMaker({
|
children: [
|
||||||
publicPath: 'src/pages/demo/plugins/',
|
|
||||||
namePrefix: 'demo-plugins-',
|
]
|
||||||
req: require.context('@/pages/demo/plugins', true, /page\.vue$/)
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
// 登陆
|
// 登陆
|
||||||
{
|
{
|
||||||
@@ -69,9 +39,7 @@ const routes = [
|
|||||||
|
|
||||||
console.log(routes)
|
console.log(routes)
|
||||||
|
|
||||||
let router = new VueRouter({
|
let router = new VueRouter({ routes })
|
||||||
routes
|
|
||||||
})
|
|
||||||
|
|
||||||
router.beforeEach((to, from, next) => {
|
router.beforeEach((to, from, next) => {
|
||||||
// 需要身份校验
|
// 需要身份校验
|
||||||
|
|||||||
Reference in New Issue
Block a user