uni-app 在iOS11.4.1系统组件中,uni.reLaunch 不会跳转

uni-app 在iOS11.4.1系统组件中,uni.reLaunch 不会跳转

开发环境 版本号 项目创建方式
Windows HBuilderX
# 操作步骤:

组件login.vue:

```html
<button [@click](/user/click)="test">login</button>  

test(){  
//...省略了请求  
//期间用了数组concat、findIndex、find  

uni.setStorage({  
   key: "token",  
   data: "123"  
});  
this.$u.toast("登录成功")  
setTimeout(() => {  
    uni.reLaunch({  
       url: "/pages/index/index"  
    })  
}, 200)  
}

index.vue:

onLoad(){  

  let token = uni.getStorageSync("token");  
  if(token){  
    uni.reLaunch({  
      url: '/pages/login/login'  
   })  
  }  

}

预期结果:

会正常跳转首页

实际结果:

偶尔能正常跳转首页,但是有时候就是不行!!!!!

bug描述:

在其他机型是没有问题的,但是在iPhone6 PLUS 系统11.4中,刚开始能正常登录,最后 token 失效后,重新登录后,提示登录成功后,一直不会跳转。

我很认真检查了11.4中js 有没有api不兼容问题

我login中无非用了 findfindIndexconcat

我用Safari Technology Preview 模拟了环境11.4环境和 在模拟器11.4版本模拟了,都是正常登录的。但是在发布后,就会这样


更多关于uni-app 在iOS11.4.1系统组件中,uni.reLaunch 不会跳转的实战教程也可以访问 https://www.itying.com/category-93-b0.html

4 回复

1111

更多关于uni-app 在iOS11.4.1系统组件中,uni.reLaunch 不会跳转的实战教程也可以访问 https://www.itying.com/category-93-b0.html


我测试是可以呢

您好,请问也是11.4系统下吗?我在其他系统是没问题的。但是就有一个用户跳转不了…

这是一个典型的 iOS 11.4.1 系统兼容性问题,主要与 uni.reLaunch 在该系统版本下的执行机制有关。

问题分析:

  1. iOS 11.4.1 系统限制:该版本对页面跳转有更严格的限制,特别是在连续调用跳转API时容易出现阻塞。
  2. 跳转冲突:你的代码在 login.vue 中通过 setTimeout 延迟执行 uni.reLaunch,同时在 index.vueonLoad 中也调用了 uni.reLaunch。当两个跳转指令时间接近时,iOS 11.4.1 可能无法正确处理这种快速连续的页面重定向。

解决方案:

方案一:优化跳转逻辑(推荐)index.vue 中,将跳转逻辑移到 onShow 生命周期,并添加防抖处理:

onShow() {
  let token = uni.getStorageSync("token");
  if(!token && this.$route.path !== '/pages/login/login') {
    uni.reLaunch({
      url: '/pages/login/login'
    })
  }
}

方案二:增加跳转延迟login.vue 中增加延迟时间:

setTimeout(() => {
  uni.reLaunch({
    url: "/pages/index/index"
  })
}, 500) // 从200ms增加到500ms

方案三:使用条件跳转login.vue 跳转前检查当前页面:

setTimeout(() => {
  const pages = getCurrentPages()
  if(pages.length && pages[pages.length-1].route !== 'pages/index/index') {
    uni.reLaunch({
      url: "/pages/index/index"
    })
  }
}, 200)
回到顶部