index.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { createRouter, createWebHashHistory } from 'vue-router'
  2. import Home from '@/pages/home/index.vue'
  3. import Category from '@/pages/category/index.vue'
  4. import Login from '@/pages/login/index.vue'
  5. import Register from '@/pages/register/index.vue'
  6. const routes = [
  7. {
  8. path: '/',
  9. redirect: '/category',
  10. component: Home,
  11. meta: {
  12. title: '首页'
  13. },
  14. children: [
  15. {
  16. path: '/category',
  17. component: Category,
  18. meta: {
  19. title: '首页'
  20. }
  21. },
  22. {
  23. path: '/goods',
  24. component: () => import('@/pages/goods/index.vue'),
  25. meta: {
  26. title: '商品详情'
  27. }
  28. },
  29. {
  30. path: '/train',
  31. component: () => import('@/pages/train/index.vue'),
  32. meta: {
  33. title: '培训'
  34. }
  35. },
  36. {
  37. path: '/branch',
  38. component: () => import('@/pages/branch/index.vue'),
  39. meta: {
  40. title: '分支'
  41. }
  42. }
  43. ]
  44. },
  45. {
  46. path: '/login',
  47. component: Login,
  48. meta: {
  49. title: '登录'
  50. }
  51. },
  52. {
  53. path: '/register',
  54. component: Register,
  55. meta: {
  56. title: '注册'
  57. }
  58. }
  59. ]
  60. const router = createRouter({
  61. history: createWebHashHistory(),
  62. routes
  63. })
  64. router.afterEach((to, before) => {
  65. document.title = to.meta?.title || '';
  66. })
  67. export default router