routes.js 1.7 KB
/*
 * @Descripttion:
 * @version:
 * @Author: limin
 * @Date: 2021-06-09 10:59:31
 * @LastEditors: limin
 * @LastEditTime: 2021-07-06 12:27:30
 */
const routesKeys = Object.freeze([
  {
    name: 'PermissionDennied',
    path: 'home/dennied',
    meta: {
      title: '无访问权限',
      isNoBack: true
    }
  },
  {
    name: 'Home',
    path: 'home/index',
    meta: {
      title: '首页',
      deepth: 1, // 标识路由的深度 数字越大深度越深 (用于判断路由的前进与返回)
      keepAlive: false
    }
  },
  {
    name: 'Work',
    path: 'work/index',
    meta: {
      title: '测试',
      deepth: 1, // 标识路由的深度 数字越大深度越深 (用于判断路由的前进与返回)
      keepAlive: false
    }
  },
  {
    name: 'Test',
    path: 'work/sub/index',
    meta: {
      title: 'test',
      deepth: 1, // 标识路由的深度 数字越大深度越深 (用于判断路由的前进与返回)
      keepAlive: false
    }
  }
])
const keepAlives = []
const children = routesKeys.map(key => {
  const { name, params, meta, path, redirect } = key
  if (meta && meta.keepAlive) {
    keepAlives.push(name)
  }
  let _path = `/${path.replace(/sub\/|\/index/g, '')}`
  if (params) {
    _path = `${_path}/:${params}`
  }
  console.log(_path)
  return {
    path: _path,
    redirect,
    name,
    component: resolve => require([`views/${path}.vue`], resolve),
    meta
  }
})

const routes = [
  {
    path: '/',
    component: resolve => require([`views/layouts/index`], resolve),
    redirect: '/home',
    meta: {
      title: '首页',
      keepAlive: false
    },
    children
  }
]
routes.push({ path: '*', redirect: '/home' })
export const keeps = keepAlives
export default routes