index.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import Vue from 'vue'
  2. import Router from 'vue-router'
  3. import Layout from '@/pages/layout'
  4. import Map from '@/pages/map'
  5. import List from '@/pages/list'
  6. import Home from '@/pages/home'
  7. import Search from '@/pages/search'
  8. import External from '@/pages/External'
  9. Vue.use(Router)
  10. // let isLocal = process.env.isLocal
  11. let isLocal = Vue.$isLocal
  12. let routes = [
  13. {
  14. path: '/',
  15. name: 'mainLayout',
  16. component: Layout,
  17. children: [
  18. {
  19. path: '/',
  20. name: 'home',
  21. component: Home
  22. },
  23. {
  24. path: '/list/:title/:type',
  25. name: 'list',
  26. component: List,
  27. children: [
  28. {name: 'item', path: ':show'}
  29. ]
  30. }
  31. ]
  32. },
  33. {
  34. path: '/search',
  35. name: 'search',
  36. component: Search
  37. },
  38. {
  39. path: '/external/:url/:id',
  40. name: 'external',
  41. component: External
  42. }
  43. ]
  44. isLocal || routes[0].children.push(
  45. {
  46. path: '/map/:title',
  47. name: 'map',
  48. component: Map,
  49. children: [
  50. {name: 'info', path: ':show'}
  51. ]
  52. }
  53. )
  54. const router = new Router({
  55. routes,
  56. scrollBehavior (to, from, savedPosition) {
  57. if (to.hash === '') {
  58. return { x: 0, y: 0 }
  59. } else {
  60. return false
  61. }
  62. }
  63. })
  64. global.paths = []
  65. router.beforeEach((to, from, next) => {
  66. global.paths.push(from)
  67. next()
  68. })
  69. global.setExternalUrl = (url) => {
  70. router.push({name: 'external', params: {url: url}})
  71. }
  72. export default router