router.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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']
  13. router.beforeEach((to, from, next) => {
  14. let isWallet= tokenpocketBnb.isInstall()
  15. console.log('isWallet:'+isWallet)
  16. if(isWallet){
  17. let token = to.query.token;
  18. if (token) {
  19. uni.setStorageSync('token',token);
  20. }
  21. const userToken = uni.getStorageSync('token')
  22. if(!userToken ){
  23. if(whiteList.indexOf(to.path)<0){
  24. next('/pages/login/index');
  25. }
  26. }
  27. console.log('前置守卫to----------', to)
  28. next();
  29. }else {
  30. console.log(to.path)
  31. if(to.path!=='/pages/index/error'){
  32. // next('/pages/index/error');
  33. }
  34. console.log('验证失败执行到错误页面')
  35. //
  36. next();
  37. }
  38. });
  39. // 全局路由后置守卫
  40. router.afterEach((to, from) => {
  41. console.log('后置守卫to------', to)
  42. })
  43. export {
  44. router,
  45. RouterMount
  46. }