index.js 770 B

12345678910111213141516171819202122232425262728293031323334
  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. next()
  22. }else{
  23. next({ path: '/pages/login/login'})
  24. }
  25. }
  26. })
  27. // 全局路由后置守卫
  28. router.afterEach((to, from) => {
  29. console.log("afterEach")
  30. })
  31. export default router;