router.js
2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* @Descripttion:
* @version:
* @Author: limin
* @Date: 2021-06-09 10:59:50
* @LastEditors: limin
* @LastEditTime: 2021-06-29 14:51:39
*/
import Vue from 'vue'
import Router from 'vue-router'
import routes from './routes'
import store from '@/store'
// hack router push callback
const originalPush = Router.prototype.push
Router.prototype.push = function push(location, onResolve, onReject) {
if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
return originalPush.call(this, location).catch(err => err)
}
Vue.use(Router)
const router = createRouter()
function createRouter() {
return new Router({
// mode: 'history', // 如果是 history模式 需要配置vue.config.js publicPath
base: 'dj-carlife-web-alipay',
// base: process.env.BASE_URL,
scrollBehavior: function(to, from, savedPosition) {
return savedPosition || { x: 0, y: 0 }
},
routes
})
}
// http://scrm.dev.glsx.com.cn/dj-scrm-wx-work-attachment-activity/
router.beforeEach((to, from, next) => {
// // 判断当前浏览器环境 不是支付宝就跳转提示页面
const AlipayClient = /AlipayClient/.test(window.navigator.userAgent)
// console.log(AlipayClient)
if (!AlipayClient && to.path !== '/tipsPage') return next('/tipsPage')
// if (/MicroMessenger/.test(window.navigator.userAgent)) {
// alert('微信客户端')
// } else if () {
// alert('支付宝客户端')
// } else {
// alert('其他浏览器')
// }
/* 路由发生变化修改页面title */
console.log('meta', to)
if (to.meta.title) {
store.dispatch('setPageMeta', to.meta)
} else {
store.dispatch('setPageMeta', { title: '活动中心' })
}
store.commit('SET_LAST_PATH', to.name)
/* 路由发生变化修改页面背景色 */
if (to.meta.backgroundColor) document.documentElement.style.backgroundColor = to.meta.backgroundColor
// if (to.matched.some(recode => recode.meta.noAuth)) {
// store.state.app.showWindow = true
// } else {
// store.dispatch('navigation')
// }
next()
})
// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
const newRouter = createRouter()
router.matcher = newRouter.matcher // reset router
}
export default router