chore: init read-star monorepo
This commit is contained in:
41
apps/user/build/plugins/router.ts
Normal file
41
apps/user/build/plugins/router.ts
Normal file
@ -0,0 +1,41 @@
|
||||
import type { RouteKey } from '@elegant-router/types'
|
||||
import type { RouteMeta } from 'vue-router'
|
||||
import ElegantVueRouter from '@elegant-router/vue/vite'
|
||||
|
||||
export function setupElegantRouter() {
|
||||
return ElegantVueRouter({
|
||||
layouts: {
|
||||
base: 'src/layouts/base-layout/index.vue',
|
||||
blank: 'src/layouts/blank-layout/index.vue',
|
||||
},
|
||||
routePathTransformer(routeName, routePath) {
|
||||
const key = routeName as RouteKey
|
||||
|
||||
if (key === 'login') {
|
||||
const modules: UnionKey.LoginModule[] = ['pwd-login', 'code-login', 'register', 'reset-pwd', 'bind-wechat']
|
||||
|
||||
const moduleReg = modules.join('|')
|
||||
|
||||
return `/login/:module(${moduleReg})?`
|
||||
}
|
||||
|
||||
return routePath
|
||||
},
|
||||
onRouteMetaGen(routeName) {
|
||||
const key = routeName as RouteKey
|
||||
|
||||
const constantRoutes: RouteKey[] = ['login', '403', '404', '500']
|
||||
|
||||
const meta: Partial<RouteMeta> = {
|
||||
title: key,
|
||||
i18nKey: `route.${key}` as App.I18n.I18nKey,
|
||||
}
|
||||
|
||||
if (constantRoutes.includes(key)) {
|
||||
meta.constant = true
|
||||
}
|
||||
|
||||
return meta
|
||||
},
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user