router.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. import tokenpocketBnb from "@/common/wallet/tokenpocket-wallet/tokenpocket-bnb";
  7. const router = createRouter({
  8. platform: process.env.VUE_APP_PLATFORM,
  9. routes: [...ROUTES]
  10. });
  11. //全局路由前置守卫
  12. const whiteList = ['/','/pages/index/error','/pages/login/register','/pages/login/index','/pages/index/index']
  13. router.beforeEach((to, from, next) => {
  14. if(to.path!=='/pages/index/error'){
  15. let token = to.query.token;
  16. let inviteCode = to.query.inviteCode;
  17. if (token) {
  18. uni.setStorageSync('token',token);
  19. }
  20. if (inviteCode) {
  21. uni.setStorageSync('inviteCode',inviteCode);
  22. }
  23. const userToken = uni.getStorageSync('token')
  24. if(!userToken ){
  25. if(whiteList.indexOf(to.path)<0){
  26. next('/pages/login/index');
  27. }
  28. }
  29. next();
  30. }else {
  31. next();
  32. }
  33. });
  34. // 全局路由后置守卫
  35. router.afterEach((to, from) => {
  36. console.log('后置守卫to------', to)
  37. if(to.path!=='/pages/index/error'){
  38. }
  39. })
  40. export {
  41. router,
  42. RouterMount
  43. }