router.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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_video',
  18. 'document_vue',
  19. 'document_vite',
  20. 'document_unocss',
  21. 'document_naive',
  22. 'document_pro-naive',
  23. 'document_antd',
  24. 'document_alova'
  25. ]
  26. },
  27. routePathTransformer(routeName, routePath) {
  28. const key = routeName as RouteKey;
  29. if (key === 'login') {
  30. const modules: UnionKey.LoginModule[] = ['pwd-login', 'code-login', 'register', 'reset-pwd', 'bind-wechat'];
  31. const moduleReg = modules.join('|');
  32. return `/login/:module(${moduleReg})?`;
  33. }
  34. return routePath;
  35. },
  36. onRouteMetaGen(routeName) {
  37. const key = routeName as RouteKey;
  38. const constantRoutes: RouteKey[] = ['login', '403', '404', '500'];
  39. const meta: Partial<RouteMeta> = {
  40. title: key,
  41. i18nKey: `route.${key}` as App.I18n.I18nKey
  42. };
  43. if (constantRoutes.includes(key)) {
  44. meta.constant = true;
  45. }
  46. return meta;
  47. }
  48. });
  49. }