index.js 913 B

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