uni-app uni.reLaunch跳转不生效
uni-app uni.reLaunch跳转不生效
| 开发环境 | 版本号 | 项目创建方式 |
|---|---|---|
| Mac | 12.1 | HBuilderX |
示例代码:
,error => {
console.log("请重新登录");
uni.clearStorage();
uni.reLaunch({
url: '/pages/login/login.vue'
});
console.log("跳转登录页");
reject("重新登录");
});
操作步骤:
调用接口request返回中调用即可
预期结果:
跳转登录
实际结果:
不跳转,但log信息都有
bug描述:
接口返回时统一判断登录token失效然后跳转登录页,最后无法跳转,url是没问题的。
uni.reLaunch({url: '/xxx'});
更多关于uni-app uni.reLaunch跳转不生效的实战教程也可以访问 https://www.itying.com/category-93-b0.html
4 回复
没有复现问题,请提供一个简单完整的测试工程
或者检查是否跳转的页面是否有继续跳转逻辑
跳转页面是不需要文件扩展名的,url: ‘/pages/login/login.vue’ 这行代码中的 .vue 删除即可
更多关于uni-app uni.reLaunch跳转不生效的实战教程也可以访问 https://www.itying.com/category-93-b0.html
确实是这个问题,不过hx工具自动补齐的,也能点进,所以就没考虑这的问题。(这个hx自动补齐问题你们已经在处理了)
看头像你们貌似是一个人,哈哈哈
问题分析:
根据你的描述,uni.reLaunch 在接口返回的回调中不生效,但 console.log 能正常执行。这通常是由于 页面栈管理 或 异步时序 问题导致的。uni.reLaunch 会关闭所有页面并打开新页面,但在某些异步回调中直接调用可能会被框架拦截或忽略。
解决方案:
- 使用
setTimeout包裹跳转(最常用且稳定): 将uni.reLaunch放入setTimeout中,确保跳转操作在下一个事件循环中执行,避免与当前执行栈冲突。,error => { console.log("请重新登录"); uni.clearStorage(); setTimeout(() => { uni.reLaunch({ url: '/pages/login/login.vue' }); }, 0); console.log("跳转登录页"); reject("重新登录"); });

