index.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { createRouter, createWebHashHistory } from 'vue-router'
  2. import HomeView from '../views/HomeView.vue'
  3. import MoreContent from '../views/MoreContent.vue'
  4. import ShuangGou from '../views/ShuangGou.vue'
  5. import PaintingDetail from '../views/PaintingDetail'
  6. // import store from '@/store/index.js'
  7. const routes = [
  8. // {
  9. // path: '/',
  10. // redirect: '/home',
  11. // },
  12. {
  13. path: '/',
  14. name: 'HomeView',
  15. component: HomeView,
  16. },
  17. {
  18. path: '/more-content',
  19. name: 'MoreContent',
  20. component: MoreContent,
  21. // component: TEXT,
  22. },
  23. {
  24. path: '/shuang-gou',
  25. name: 'ShuangGou',
  26. component: ShuangGou,
  27. },
  28. {
  29. path: '/painting-detail',
  30. name: 'PaintingDetail',
  31. component: PaintingDetail,
  32. // component: TEXT,
  33. },
  34. ]
  35. const router = createRouter({
  36. history: createWebHashHistory(),
  37. routes
  38. })
  39. router.beforeEach((to, from) => {
  40. // 生产环境下强制每次都从首页进入
  41. if (process.env.NODE_ENV === 'production' && !from.name && to.name !== 'HomeView') {
  42. return '/'
  43. }
  44. })
  45. export default router