FenXiNspUniapp/common/router/index.js

34 lines
852 B
JavaScript

import modules from './modules'
import Vue from 'vue'
import Router from '@/plugin/uni-simple-router/index.js'
import {ACCESS_TOKEN} from '@/common/util/constants.js'
Vue.use(Router)
//初始化
const router = new Router({
encodeURI:true,
routes: [...modules]//路由表
});
const whiteList = ['/packDetail/pages/login/login','/pages/index/index']
//全局路由前置守卫
router.beforeEach((to, from, next) => {
const Access_Token = uni.getStorageSync('Access-Token')
let third_session=uni.getStorageSync('third_session');
if(third_session){
next()
}else{
if (whiteList.indexOf(to.path) !== -1) {
next()
}else{
next({ path: '/pages/index/index'})
// next({ path: '/packDetail/pages/login/login'})
}
}
})
// 全局路由后置守卫
router.afterEach((to, from) => {
console.log("afterEach")
})
export default router;