index.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import { createRouter, createWebHistory, createWebHashHistory, RouteRecordRaw } from 'vue-router'
  2. // 主要tabbar
  3. export const layoutRoutes: Array<RouteRecordRaw> = [
  4. {
  5. path: '/',
  6. name: 'home',
  7. meta: {
  8. title: 'home',
  9. keepAlive: true,
  10. },
  11. component: () => import('@/views/home/index.vue'),
  12. },
  13. {
  14. path: '/category',
  15. name: 'category',
  16. meta: {
  17. title: 'category',
  18. // keepAlive: true,
  19. },
  20. component: () => import('@/views/category/index.vue'),
  21. },
  22. {
  23. path: '/mycenter',
  24. name: 'mycenter',
  25. meta: {
  26. title: 'mycenter',
  27. },
  28. component: () => import('@/views/mycenter/index.vue'),
  29. },
  30. {
  31. path: '/shopcart',
  32. name: 'shopcart',
  33. meta: {
  34. title: 'shopcart',
  35. },
  36. component: () => import('@/views/shopcart/index.vue'),
  37. },
  38. ]
  39. export const routes: Array<RouteRecordRaw> = [
  40. {
  41. path: '/',
  42. component: () => import('@/layout/index.vue'),
  43. redirect: '/index',
  44. // 需要layout的页面
  45. children: layoutRoutes,
  46. },
  47. {
  48. path: '/login',
  49. name: 'login',
  50. component: () => import('@/views/login/index.vue'),
  51. },
  52. {
  53. path: '/webrtc',
  54. name: 'webrtc',
  55. component: () => import('@/views/webrtc/index.vue'),
  56. },
  57. {
  58. path: '/account',
  59. name: 'account',
  60. component: () => import('@/views/account.vue'),
  61. },
  62. // 替代vue2中的'*'通配符路径
  63. { path: '/:pathMatch(.*)*', redirect: '/' },
  64. ]
  65. const router = createRouter({
  66. scrollBehavior: () => ({ left: 0, top: 0 }),
  67. history: createWebHashHistory(),
  68. routes,
  69. })
  70. router.beforeEach((_to, _from, next) => {
  71. next()
  72. })
  73. export default router