index.js 866 B

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