router.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // router.js
  2. import { RouterMount, createRouter } from 'uni-simple-router';
  3. import tools from '@/common/js/tools'
  4. import store from '@/store/index'
  5. import { getPlatform } from '@/common/js/utils'
  6. const router = createRouter({
  7. platform: process.env.VUE_APP_PLATFORM,
  8. routes: [...ROUTES]
  9. });
  10. //全局路由前置守卫
  11. const whiteList = ['/','/pages/index/index','/pages/text/index']
  12. router.beforeEach((to, from, next) => {
  13. let token = to.query.token;
  14. let m_id = to.query.m_id;
  15. if (token && m_id) {
  16. // store.commit("setCookie", { 'token': token, 'm_id': m_id });
  17. uni.setStorageSync('token',token);
  18. uni.setStorageSync('m_id',m_id);
  19. next('/pages/index/index');
  20. }
  21. const userToken = uni.getStorageSync('token')
  22. const userMid = uni.getStorageSync('m_id')
  23. console.log('登陆信息-------'+userToken+'--------------'+userMid)
  24. if((!userToken || !userMid) && whiteList.indexOf(to.fullPath)<0){
  25. console.log('暂无登陆信息')
  26. console.log(to.fullPath )
  27. if(to.fullPath!=='/pages/login/index'){
  28. next('/pages/login/index');
  29. }
  30. }
  31. console.log('前置守卫to----------', to)
  32. next();
  33. });
  34. // 全局路由后置守卫
  35. router.afterEach((to, from) => {
  36. console.log('后置守卫to------', to)
  37. })
  38. export {
  39. router,
  40. RouterMount
  41. }