router.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import Vue from 'vue';
  2. import Router from 'uni-simple-router';
  3. Vue.use(Router)
  4. import utils from '../utils/common.js'
  5. //初始化
  6. const router = new Router({
  7. routes:ROUTES //路由表
  8. });
  9. const filters = ['/pages/auth/login','/pages/common/launch']
  10. //进入的路由 要出去的路由
  11. router.beforeEach((to, from, next) => {
  12. console.log("路由进入")
  13. console.log(to)
  14. let index = filters.indexOf(to.path);
  15. //过滤
  16. console.log(index)
  17. if (index > -1) {
  18. next();
  19. return;
  20. }
  21. var data=utils.isLogin();
  22. console.log(data)
  23. if(utils.isLogin()){
  24. console.log("ok")
  25. next();
  26. }
  27. else{
  28. next({path: "/pages/auth/login"});
  29. }
  30. //判断是否校验路由
  31. // if (to.meta.isAure) {
  32. // let name = sessionStorage.getItem('username');
  33. // //有状态,并且存在sessionStorage,则next,否则返回登陆页面
  34. // if (name) {
  35. // next();
  36. // } else {
  37. // next({path: "/login",query:{redirect:to.name}});
  38. // }
  39. // } else {
  40. // next();
  41. // }
  42. });
  43. export default router;