router.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. // store.commit("setCookie", { 'token': token, 'm_id': m_id });
  14. uni.setStorageSync('token',token);
  15. uni.setStorageSync('m_id',m_id);
  16. next('/pages/index/index');
  17. }
  18. const userToken = uni.getStorageSync('token')
  19. const userMid = uni.getStorageSync('m_id')
  20. console.log('登陆信息-------'+userToken+'--------------'+userMid)
  21. if((!userToken || !userMid) && whiteList.indexOf(to.fullPath)<0){
  22. console.log('暂无登陆信息')
  23. console.log(to.fullPath )
  24. if(to.fullPath!=='/pages/login/index'){
  25. next('/pages/login/index');
  26. }
  27. }
  28. console.log('前置守卫to----------', to)
  29. next();
  30. });
  31. // 全局路由后置守卫
  32. router.afterEach((to, from) => {
  33. console.log('后置守卫to------', to)
  34. })
  35. export {
  36. router,
  37. RouterMount
  38. }