index.js 771 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. } else {
  21. if (to.name == 'login') {
  22. next()
  23. } else if (to.name == 'zhuce') {
  24. next()
  25. } else {
  26. next({
  27. name: "login"
  28. })
  29. }
  30. if (whiteList.indexOf(to.path) !== -1) {
  31. } else {
  32. }
  33. }
  34. })
  35. // 全局路由后置守卫
  36. router.afterEach((to, from) => {})
  37. export default router;