index.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import { createRouter, createWebHistory } from 'vue-router'
  2. import { useParentPathStore } from '@/stores/modules/parentPath'
  3. const router = createRouter({
  4. history: createWebHistory(import.meta.env.BASE_URL),
  5. routes: [
  6. {
  7. path: '/',
  8. name: 'Home',
  9. redirect: '/booking',
  10. component: () => import('../views/Layout'),
  11. children: [
  12. {
  13. path: '/dashboard',
  14. name: 'Dashboard',
  15. component: () => import('../views/Dashboard')
  16. },
  17. {
  18. path: '/booking',
  19. name: 'Booking',
  20. component: () => import('../views/Booking')
  21. },
  22. {
  23. path: '/booking/detail',
  24. name: 'Booking Detail',
  25. component: () => import('../views/Booking/src/components/BookingDetail'),
  26. meta: {
  27. parentPath: '/booking'
  28. }
  29. },
  30. {
  31. path: '/tracking',
  32. name: 'Tracking',
  33. component: () => import('../views/Tracking')
  34. },
  35. {
  36. path: '/tracking/detail',
  37. name: 'Tracking Detail',
  38. component: () => import('../views/Tracking/src/components/TrackingDetail')
  39. },
  40. {
  41. path: '/public-tracking',
  42. name: 'Public Tracking',
  43. component: () => import('../views/Tracking/src/components/PublicTracking')
  44. },
  45. {
  46. path: '/public-tracking/detail',
  47. name: 'Public Tracking Detail',
  48. component: () =>
  49. import(
  50. '../views/Tracking/src/components/PublicTracking/src/components/PublicTrackingDetail.vue'
  51. )
  52. },
  53. {
  54. path: '/login',
  55. name: 'Login',
  56. component: () => import('../views/Login')
  57. },
  58. {
  59. path: '/Operationlog',
  60. name: 'Operationlog',
  61. component: () => import('../views/OperationLog')
  62. }
  63. ]
  64. }
  65. ]
  66. })
  67. // * 路由拦截 beforeEach
  68. router.beforeEach(async (to, from, next) => {
  69. const parentPathStore = useParentPathStore()
  70. if (to.path.includes('/detail')) {
  71. parentPathStore.setParentPath(from)
  72. } else {
  73. parentPathStore.clearParentPath()
  74. }
  75. next()
  76. })
  77. export default router