123456789101112131415161718192021222324252627282930313233343536 |
- // router.js
- import { RouterMount, createRouter } from 'uni-simple-router';
- const router = createRouter({
- platform: process.env.VUE_APP_PLATFORM,
- routes: [...ROUTES]
- });
- //全局路由前置守卫
- const whiteList = ['/','/pages/index/index','/pages/text/index']
- router.beforeEach((to, from, next) => {
- let token = to.query.token;
- let m_id = to.query.m_id;
- if (token && m_id) {
- uni.setStorageSync('token',token);
- uni.setStorageSync('m_id',m_id);
- next('/pages/index/index');
- }
- const userToken = uni.getStorageSync('token')
- const userMid = uni.getStorageSync('m_id')
- if((!userToken || !userMid) && whiteList.indexOf(to.fullPath)<0){
- if(to.fullPath!=='/pages/login/index'){
- // next('/pages/login/index');
- }
- }
- next();
- });
- // 全局路由后置守卫
- router.afterEach((to, from) => {
- // console.log('后置守卫to------', to)
- })
- export {
- router,
- RouterMount
- }
|