router.js 967 B

123456789101112131415161718192021222324252627282930313233343536
  1. // router.js
  2. import { RouterMount, createRouter } from 'uni-simple-router';
  3. const router = createRouter({
  4. platform: process.env.VUE_APP_PLATFORM,
  5. routes: [...ROUTES]
  6. });
  7. //全局路由前置守卫
  8. const whiteList = ['/','/pages/index/index','/pages/text/index']
  9. router.beforeEach((to, from, next) => {
  10. let token = to.query.token;
  11. let m_id = to.query.m_id;
  12. if (token && m_id) {
  13. uni.setStorageSync('token',token);
  14. uni.setStorageSync('m_id',m_id);
  15. next('/pages/index/index');
  16. }
  17. const userToken = uni.getStorageSync('token')
  18. const userMid = uni.getStorageSync('m_id')
  19. if((!userToken || !userMid) && whiteList.indexOf(to.fullPath)<0){
  20. if(to.fullPath!=='/pages/login/index'){
  21. // next('/pages/login/index');
  22. }
  23. }
  24. next();
  25. });
  26. // 全局路由后置守卫
  27. router.afterEach((to, from) => {
  28. // console.log('后置守卫to------', to)
  29. })
  30. export {
  31. router,
  32. RouterMount
  33. }