index.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import sharedService from './../services/shared.service';
  2. import { createRouter, createWebHashHistory } from '@ionic/vue-router';
  3. import { NavigationGuardNext, RouteLocationNormalized, RouteRecordRaw } from 'vue-router';
  4. const routes: Array<RouteRecordRaw> = [
  5. {
  6. path: '',
  7. redirect: '/home',
  8. },
  9. {
  10. path: '/home',
  11. name: 'Home',
  12. component: () => import('../views/common/HomePage.vue'),
  13. },
  14. {
  15. path: '/login',
  16. name: 'Login',
  17. component: () => import('../views/common/LoginPage.vue'),
  18. },
  19. {
  20. path: '/as',
  21. redirect: '/as/defting',
  22. },
  23. {
  24. path: '/as/defting',
  25. component: () => import('../views/as/AsDeftIngPage.vue'),
  26. },
  27. {
  28. path: '/as/defting/:id',
  29. component: () => import('../views/as/AsDeftIngViewPage.vue'),
  30. },
  31. {
  32. path: '/as/deftdone',
  33. component: () => import('../views/as/AsDeftDonePage.vue'),
  34. },
  35. {
  36. path: '/as/deftdone/:id',
  37. component: () => import('../views/as/AsDeftDoneViewPage.vue'),
  38. },
  39. {
  40. path: '/po',
  41. redirect: '/po/deftmang',
  42. },
  43. {
  44. path: '/po/deftmang',
  45. component: () => import('../views/po/PoDeftMangPage.vue'),
  46. },
  47. {
  48. path: '/po/deftmang/:id',
  49. component: () => import('../views/po/PoDeftMangViewPage.vue'),
  50. },
  51. {
  52. path: '/po/deftque',
  53. component: () => import('../views/po/PoDeftQuePage.vue'),
  54. },
  55. {
  56. path: '/po/deftque/:id',
  57. component: () => import('../views/po/PoDeftQueViewPage.vue'),
  58. },
  59. {
  60. path: '/po/roomrev',
  61. component: () => import('../views/po/PoRoomRevPage.vue'),
  62. },
  63. {
  64. path: '/po/roomapp',
  65. component: () => import('../views/po/PoRoomAppPage.vue'),
  66. },
  67. {
  68. path: '/address',
  69. component: () => import('../views/common/SiteAddressPage.vue'),
  70. },
  71. {
  72. path: '/pushdev',
  73. component: () => import('../views/common/PushDevPage.vue'),
  74. },
  75. {
  76. path: '/sample',
  77. component: () => import('../views/common/SamplePage.vue'),
  78. },
  79. {
  80. path: '/test',
  81. component: () => import('../views/common/SamplePage.vue'),
  82. },
  83. {
  84. path: '/error',
  85. component: () => import('../views/common/ErrorPage.vue'),
  86. },
  87. {
  88. path: '/:pathMatch(.*)*',
  89. redirect: '/home',
  90. },
  91. ];
  92. const router = createRouter({
  93. history: createWebHashHistory(process.env.BASE_URL),
  94. routes,
  95. });
  96. router.beforeEach(async (to: RouteLocationNormalized, _: RouteLocationNormalized, next: NavigationGuardNext) => {
  97. if (!to.path.startsWith('/login') && !['/error', '/test', '/sample'].includes(to.path)) {
  98. const path = await sharedService.isLogined(to.path);
  99. switch (path) {
  100. case '/login':
  101. next({ path: '/login', name: 'Login', query: { next: to.path } });
  102. break;
  103. default:
  104. if (!to.path.startsWith(path)) {
  105. next({ path: path });
  106. } else {
  107. next();
  108. }
  109. break;
  110. }
  111. } else {
  112. next();
  113. }
  114. });
  115. export default router;