index.js 839 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import modules from './modules'
  2. import Vue from 'vue'
  3. import Router from '@/plugin/uni-simple-router/index.js'
  4. import {
  5. ACCESS_TOKEN,
  6. USER_INFO
  7. } from '@/common/util/constants.js'
  8. Vue.use(Router)
  9. //初始化
  10. const router = new Router({
  11. encodeURI: true,
  12. routes: [...modules] //路由表
  13. });
  14. const whiteList = ['/pages/login/login']
  15. //全局路由前置守卫
  16. router.beforeEach((to, from, next) => {
  17. let token = uni.getStorageSync(ACCESS_TOKEN);
  18. if (token) {
  19. next()
  20. console.log(true)
  21. } else {
  22. console.log(false)
  23. if (to.name == 'login') {
  24. next()
  25. } else if (to.name == 'zhuce') {
  26. next()
  27. } else {
  28. next({
  29. name: "login"
  30. })
  31. }
  32. if (whiteList.indexOf(to.path) !== -1) {
  33. } else {
  34. }
  35. }
  36. })
  37. // 全局路由后置守卫
  38. router.afterEach((to, from) => {
  39. console.log("afterEach")
  40. })
  41. export default router;