import System from '@/utils/System'
import { createRouter, createWebHashHistory } from 'vue-router'
import CRouter from './CRouter'
/**
* 默认主题
*/
const themeList = ['light', 'dark'] as any[]
const defaultTheme = 'light' as any
const diffTheme = 'dark' as any
/**
* 路由目录/src/views/light/home/index.vue、/src/views/dark/home/index.vue
*/
export const initRouter = () => {
let _modules = import.meta.glob([
'@/views/**/*.vue',
'!@/views/**/*-com/**/*.vue',
'!@/views/**/com/**/*.vue',
'!@/views/**/components/**/*.vue'
])
const _defaultModules = {} as any
const _diffModules = {} as any
Object.keys(_modules).forEach((key) => {
themeList.forEach((item) => {
if (defaultTheme != item) {
if (!new RegExp(`^/src/views/${item}`).test(key)) {
_defaultModules[key] = _modules[key]
}
if (diffTheme != defaultTheme && new RegExp(`^/src/views/${diffTheme}`).test(key)) {
_diffModules[key] = _modules[key]
}
}
})
})
const pathHook = (path: string) => {
return path
.replace(/\/index$/, '')
.replace(new RegExp(`/${defaultTheme}/`), '/')
.replace(new RegExp(`/${diffTheme}/`), '/')
}
const _routes = CRouter.init({
modules: _defaultModules,
diffModules: _diffModules,
children: [
{
path: '/layout',
component: '/layout',
childrenReg: ['^/pages']
}
],
setInfoHook(item) {
item.meta = {
title: item.path
}
},
mapKeyPathHook(path) {
return pathHook(path)
},
pathHook(path) {
return pathHook(path).replace(/^\/pages/, '')
}
})
const router = createRouter({
history: createWebHashHistory(),
routes: [
..._routes.array,
{
path: '/',
redirect: '/home'
}
]
})
System.router = router
return router
}
tools-vue3
2.0.12 • Public • Published Versions
Current Tags
Version | Downloads (Last 7 Days) | Tag |
---|---|---|
2.0.12 | 9 | latest |
Version History
Version | Downloads (Last 7 Days) | Published |
---|---|---|
2.0.12 | 9 | |
2.0.11 | 4 | |
2.0.10 | 2 | |
2.0.9 | 0 | |
2.0.8 | 0 | |
2.0.7 | 2 | |
2.0.6 | 0 | |
2.0.5 | 3 | |
2.0.4 | 1 | |
2.0.3 | 3 | |
2.0.2 | 0 | |
2.0.1 | 0 | |
2.0.0 | 0 | |
1.2.1 | 1 | |
1.2.0 | 0 | |
1.1.7 | 4 | |
1.1.6 | 0 | |
1.1.5 | 0 | |
1.1.4 | 0 | |
1.1.3 | 0 | |
1.1.2 | 0 | |
1.1.1 | 0 | |
1.1.0 | 1 | |
1.0.50 | 0 | |
1.0.49 | 1 | |
1.0.48 | 0 | |
1.0.47 | 0 | |
1.0.46 | 1 | |
1.0.45 | 1 | |
1.0.44 | 0 | |
1.0.43 | 0 | |
1.0.42 | 1 | |
1.0.41 | 0 | |
1.0.40 | 0 | |
1.0.39 | 0 | |
1.0.38 | 1 | |
1.0.37 | 0 | |
1.0.36 | 0 | |
1.0.35 | 0 | |
1.0.34 | 0 | |
1.0.33 | 1 | |
1.0.32 | 0 | |
1.0.31 | 0 | |
1.0.30 | 0 | |
1.0.29 | 0 | |
1.0.28 | 0 | |
1.0.27 | 0 | |
1.0.26 | 0 | |
1.0.25 | 0 | |
1.0.24 | 0 | |
1.0.23 | 0 | |
1.0.22 | 0 | |
1.0.21 | 0 | |
1.0.20 | 0 | |
1.0.19 | 0 | |
1.0.18 | 0 | |
1.0.17 | 0 | |
1.0.16 | 0 | |
1.0.15 | 1 | |
1.0.14 | 1 | |
1.0.13 | 0 | |
1.0.12 | 0 | |
1.0.11 | 0 | |
1.0.10 | 0 | |
1.0.9 | 0 | |
1.0.8 | 0 | |
1.0.7 | 0 | |
1.0.6 | 0 | |
1.0.5 | 0 | |
1.0.4 | 0 | |
1.0.3 | 0 | |
1.0.2 | 0 | |
1.0.1 | 0 | |
1.0.0 | 0 |
Package Sidebar
Install
npm i tools-vue3
Repository
Homepage
Weekly Downloads
33
Version
2.0.12
License
MIT
Unpacked Size
17.2 kB
Total Files
10