Files
BlockChainH5/router/index.js
唐明明 2918fcee25 merge
2021-09-30 12:57:47 +08:00

54 lines
1.0 KiB
JavaScript

/**
* Web唐明明
* 匆匆数载恍如梦,岁月迢迢华发增。
* 碌碌无为枉半生,一朝惊醒万事空。
* moduleName: router
*/
import { RouterMount, createRouter } from 'uni-simple-router';
import store from '../store/index'
const router = createRouter({
h5: {
paramsToQuery: true
},
platform: process.env.VUE_APP_PLATFORM,
routes: [...ROUTES, {
path: '*',
name:'404',
component: ()=> import('@/pages/404/404')
}]
})
// 全局路由前置守卫
router.beforeEach((to, from, next) => {
const token = store.getters.getToken || uni.getStorageSync('token')
// 检查是否需要微信授权
if(store.getters.getCode === '' && to.name != 'wxAuth'){
next({
name: 'wxAuth'
})
}
// 检查是否需要登录
if(to.auth && token === ''){
next({
name: 'Login',
params: {
toName: to.name
}
})
return
}
next();
})
// 全局路由后置守卫
router.afterEach((to, from) => {
// console.log('跳转结束--暂无应用场景')
})
export {
router,
RouterMount
}