naviInterceptor.js 423 B

12345678910111213141516171819
  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. if (!token) {
  10. uni.reLaunch({
  11. url: router.LOGIN_URL
  12. });
  13. return false; // 阻止跳转
  14. }
  15. }
  16. });
  17. };
  18. export default naviInterceptor;