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