router.js 704 B

1234567891011121314151617181920212223242526272829303132333435
  1. import store from './store'
  2. const routes = [
  3. {
  4. name: 'home',
  5. path: '/:patchNum',
  6. component: () => import(/* webpackChunkName: 'home' */ '@/components/Home'),
  7. },
  8. {
  9. name: 'report',
  10. path: '/:patchNum/report',
  11. component: () => import(/* webpackChunkName: 'report' */ '@/components/Report'),
  12. },
  13. {
  14. name: 'buy',
  15. path: '/:patchNum/buy',
  16. component: () => import(/* webpackChunkName: 'buy' */ '@/components/Buy'),
  17. },
  18. ]
  19. const router = new VueRouter({
  20. mode: 'history',
  21. routes,
  22. })
  23. router.beforeEach(async (to, from, next) => {
  24. if (!store.state.trace.patch_num) {
  25. await store.dispatch('getTrace', to.params.patchNum)
  26. }
  27. next()
  28. })
  29. export default router