index.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import Vue from 'vue'
  2. import VueRouter from 'vue-router'
  3. Vue.use(VueRouter)
  4. const routes = [
  5. {
  6. path: '/',
  7. name: 'Layout',
  8. component: () => import('../views/Layout/index.vue'),
  9. redirect: { name: 'Home' },
  10. children: [
  11. // 首页
  12. {
  13. path: '/Layout/Home',
  14. name: 'Home',
  15. component: () => import('../views/Home/index.vue'),
  16. meta: { myTitle: 'Capital Museum.China', topColor: '#74120b' },
  17. },
  18. // Visit页面
  19. {
  20. path: '/Layout/Visit/:id',
  21. name: 'Visit',
  22. component: () => import('../views/Visit/index.vue'),
  23. meta: { myTitle: 'Visit', topColor: '#c3ac8d' },
  24. },
  25. {
  26. path: '/Layout/VisitInfo',
  27. name: 'VisitInfo',
  28. component: () => import('../views/Visit/VisitInfo.vue'),
  29. meta: { myTitle: 'Reservation', topColor: '#c3ac8d' },
  30. },
  31. ]
  32. }
  33. ]
  34. const router = new VueRouter({
  35. // mode: 'history',
  36. base: process.env.BASE_URL,
  37. routes
  38. })
  39. // 导航守卫,回到页面顶部
  40. router.beforeEach((to, from, next) => {
  41. setTimeout(() => {
  42. let dom = document.querySelector('.Layout')
  43. dom.scrollTop = 0
  44. }, 100);
  45. next()
  46. })
  47. // 全局后置钩子,设置title
  48. router.afterEach(to => {
  49. // 设置title
  50. document.title = to.meta.myTitle;
  51. })
  52. export default router