router.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import type { RouteMeta } from 'vue-router';
  2. import ElegantVueRouter from '@elegant-router/vue/vite';
  3. import type { RouteKey } from '@elegant-router/types';
  4. export function setupElegantRouter() {
  5. return ElegantVueRouter({
  6. layouts: {
  7. base: 'src/layouts/base-layout/index.vue',
  8. blank: 'src/layouts/blank-layout/index.vue'
  9. },
  10. customRoutes: {
  11. names: [
  12. 'exception_403',
  13. 'exception_404',
  14. 'exception_500',
  15. 'document_project',
  16. 'document_project-link',
  17. 'document_vue',
  18. 'document_vite',
  19. 'document_unocss',
  20. 'document_naive',
  21. 'document_antd'
  22. ]
  23. },
  24. routePathTransformer(routeName, routePath) {
  25. const key = routeName as RouteKey;
  26. if (key === 'login') {
  27. const modules: UnionKey.LoginModule[] = ['pwd-login', 'code-login', 'register', 'reset-pwd', 'bind-wechat'];
  28. const moduleReg = modules.join('|');
  29. return `/login/:module(${moduleReg})?`;
  30. }
  31. return routePath;
  32. },
  33. onRouteMetaGen(routeName) {
  34. const key = routeName as RouteKey;
  35. const constantRoutes: RouteKey[] = ['login', '403', '404', '500'];
  36. const meta: Partial<RouteMeta> = {
  37. title: key,
  38. i18nKey: `route.${key}` as App.I18n.I18nKey
  39. };
  40. if (constantRoutes.includes(key)) {
  41. meta.constant = true;
  42. }
  43. return meta;
  44. }
  45. });
  46. }