naviInterceptor.js 466 B

1234567891011121314151617181920
  1. import router from "@/common/constants/router";
  2. /**
  3. * 导航拦截器
  4. */
  5. const naviInterceptor = () => {
  6. uni.addInterceptor('navigateTo', {
  7. invoke(data) {
  8. const token = uni.getStorageSync('token');
  9. console.log('token', router.LOGIN_URL);
  10. if (!token) {
  11. uni.reLaunch({
  12. url: router.LOGIN_URL
  13. });
  14. return false; // 阻止跳转
  15. }
  16. }
  17. });
  18. };
  19. export default naviInterceptor;