提交 | 用户 | age
|
3ac5f2
|
1 |
/** |
J |
2 |
* router 配置,使用路由懒加载 |
|
3 |
*/ |
|
4 |
import Vue from 'vue' |
|
5 |
import Router from 'vue-router' |
|
6 |
import Store from '../store' |
|
7 |
// import HelloWorld from '@/components/HelloWorld' |
|
8 |
|
|
9 |
Vue.use(Router) |
|
10 |
|
|
11 |
let router = new Router({ |
|
12 |
// mode: 'history', |
|
13 |
routes: [ |
|
14 |
{ |
|
15 |
path: '/', |
|
16 |
name: 'root', |
bb2b08
|
17 |
// component: () => import('@/pages/index') |
6da3c1
|
18 |
// component: () => import('@/pages/login/index') |
J |
19 |
component: () => import('@/pages/room/list') |
aeb317
|
20 |
}, |
bf4dca
|
21 |
// { |
J |
22 |
// path: '/login', |
|
23 |
// name: 'login', |
|
24 |
// component: () => import('@/pages/login/index') |
|
25 |
// }, |
|
26 |
// { |
|
27 |
// path: '/index', |
|
28 |
// name: 'index', |
|
29 |
// component: () => import('@/pages/index') |
|
30 |
// }, |
3ac5f2
|
31 |
{ |
J |
32 |
path: '/room/list', |
|
33 |
name: 'roomList', |
bf4dca
|
34 |
component: () => import('@/pages/room/list'), |
J |
35 |
meta: { title: '治疗室列表', keepAlive: true } |
3ac5f2
|
36 |
}, |
J |
37 |
{ |
|
38 |
path: '/room/detail', |
|
39 |
name: 'roomDetail', |
bf4dca
|
40 |
component: () => import('@/pages/room/detail'), |
J |
41 |
meta: { title: '治疗室详情', isPush: false } |
3ac5f2
|
42 |
} |
J |
43 |
] |
|
44 |
}) |
|
45 |
|
bf4dca
|
46 |
// 路由跳转之前 |
J |
47 |
// 是否已经跳转过房间详情 |
|
48 |
var isJumpeRoomDetail = localStorage.getItem('isJumpeRoomDetail') |
|
49 |
if (!isJumpeRoomDetail) { |
|
50 |
localStorage.setItem('isJumpeRoomDetail', '0') // 是否已经跳转过房间详情 |
|
51 |
} |
|
52 |
|
|
53 |
// 跳转房间详情 |
|
54 |
function jumpRoomDetail() { |
|
55 |
var roomId = localStorage.getItem('roomId') |
|
56 |
var isJumpeRoomDetail = localStorage.getItem('isJumpeRoomDetail') |
|
57 |
// 还没跳转且有localroomId的 |
|
58 |
// console.log('7777777777777777777777777777', isJumpeRoomDetail, roomId) |
|
59 |
if (isJumpeRoomDetail === '0' && roomId) { |
|
60 |
localStorage.setItem('isJumpeRoomDetail', '1') |
|
61 |
return { path: `./room/detail?id=${roomId}` } |
|
62 |
} else { |
|
63 |
localStorage.setItem('isJumpeRoomDetail', '1') |
|
64 |
return true |
|
65 |
} |
|
66 |
} |
|
67 |
|
|
68 |
// 路由跳转之前 |
|
69 |
router.beforeEach(function(to, from, next) { |
|
70 |
// var isJumpeRoomDetail = localStorage.getItem('isJumpeRoomDetail') |
|
71 |
// console.log('999999999999999999999999999999999', to, from, isJumpeRoomDetail) |
|
72 |
var nextPage = true // 默认true |
|
73 |
// 直接进入首页(列表页) |
|
74 |
if ((to.name === 'root' || to.name === 'roomList') && !from.name) { |
|
75 |
nextPage = jumpRoomDetail() |
|
76 |
} |
|
77 |
// 直接进入详情页 |
|
78 |
if (to.name === 'roomDetail' && !from.name) { |
|
79 |
localStorage.setItem('isJumpeRoomDetail', '1') |
|
80 |
if (to.query.id) { |
|
81 |
localStorage.setItem('roomId', to.query.id) |
|
82 |
} |
|
83 |
} |
|
84 |
|
|
85 |
// 列表页进入详情页 |
|
86 |
if (to.name === 'roomDetail' && (from.name === 'root' || from.name === 'roomList')) { |
|
87 |
localStorage.setItem('isJumpeRoomDetail', '0') |
|
88 |
if (to.query.id) { |
|
89 |
localStorage.setItem('roomId', to.query.id) |
|
90 |
} |
|
91 |
} |
|
92 |
|
|
93 |
// 详情页返回列表 |
|
94 |
if ((to.name === 'root' || to.name === 'roomList') && from.name === 'roomDetail') { |
|
95 |
localStorage.setItem('isJumpeRoomDetail', '1') |
|
96 |
} |
|
97 |
next(nextPage) |
|
98 |
}) |
|
99 |
|
3ac5f2
|
100 |
export default router |