router.js 951 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // router.js
  2. import { RouterMount, createRouter, runtimeQuit } from '@/js_sdk/hhyang-uni-simple-router/uni-simple-router';
  3. import tools from "@/service/tools";
  4. const router = createRouter({
  5. platform: process.env.VUE_APP_PLATFORM,
  6. routerErrorEach:({type,level,...args})=>{
  7. // console.log({type,level,...args})
  8. // #ifdef APP-PLUS
  9. if(type===3){
  10. router.$lockStatus=false;
  11. tools.onBackPress()
  12. }
  13. // #endif
  14. },
  15. routes: [...ROUTES]
  16. });
  17. //全局路由前置守卫
  18. const whiteList = ['/pages/login/index']
  19. router.beforeEach((to, from, next) => {
  20. const userToken = uni.getStorageSync('token')
  21. // #ifdef H5
  22. if(whiteList.indexOf(to.path)<0 && !userToken){
  23. // tools.wxLogin()
  24. }
  25. // #endif
  26. next();
  27. });
  28. // 全局路由后置守卫
  29. router.afterEach((to, from) => {
  30. // console.log('后置守卫to------', to)
  31. })
  32. export {
  33. router,
  34. RouterMount
  35. }