tools-vue3

vue3 tools
2,321
Install
npm install tools-vue3
Latest Version:2.0.12
Vue:3
License:MIT
Last Updated:Jul 2, 2025
Links: Gitee  ·  npm
Maintainer: a1518079148

vue3 工具

CRouter 复杂示例

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
}

Related Packages

gemstone-framework-frontend

Frontend Framework of Gemstone JavaScript Technology Stack

2,559 0
cc1-vue3

我来助你-vue3工具库

3,745
stellify-framework

Frontend framework built for AI code generation

2,744
build-lib

Powerful and easy to use beautiful workbench layout

3,365
m2-webui

The package is provided web components and utilities based on vue and element-ui...

969 6

Version History

Version Released Vue License
2.0.12 ^3.4.29 MIT
2.0.11 ^3.4.29 MIT
2.0.10 ^3.4.29 MIT
2.0.9 ^3.4.29 MIT
2.0.8 ^3.4.29 MIT