index.js 846 B

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