router.js 1.1 KB

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