index.js 536 B

12345678910111213141516171819202122232425
  1. import { createRouter, createWebHashHistory } from 'vue-router'
  2. import HomeView from '../views/HomeView.vue'
  3. // import store from '@/store/index.js'
  4. const routes = [
  5. {
  6. path: '/',
  7. name: 'HomeView',
  8. component: HomeView,
  9. },
  10. ]
  11. const router = createRouter({
  12. history: createWebHashHistory(),
  13. routes
  14. })
  15. router.beforeEach((to, from) => {
  16. // 生产环境下强制每次都从首页进入
  17. if (process.env.NODE_ENV === 'production' && !from.name && to.name !== 'HomeView') {
  18. return '/'
  19. }
  20. })
  21. export default router