index.js 872 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import Vue from 'vue'
  2. import VueRouter from 'vue-router'
  3. Vue.use(VueRouter)
  4. const _import = require('./import-' + process.env.NODE_ENV)
  5. const routes = [
  6. // {
  7. // path: '*',
  8. // redirect: '/404'
  9. // },
  10. {
  11. path: '/404',
  12. name: '404',
  13. component: _import('page/404/index')
  14. },
  15. {
  16. path: '/',
  17. name: 'index',
  18. component: _import('views/index/index')
  19. }
  20. ]
  21. const router = new VueRouter({
  22. mode: 'history',
  23. routes,
  24. scrollBehavior (to, from, savedPosition) {
  25. if (to.hash) {
  26. return {
  27. selector: to.hash
  28. }
  29. }
  30. // keep-alive 返回缓存页面后记录浏览位置
  31. if (savedPosition && to.meta.keepAlive) {
  32. return savedPosition
  33. }
  34. // 异步滚动操作
  35. return new Promise((resolve) => {
  36. setTimeout(() => {
  37. resolve({ x: 0, y: 1 })
  38. }, 0)
  39. })
  40. }
  41. })
  42. export default router