页面session失效,重新登录后返回提示页面路径不存在?

小程序 文章 2022-02-16 09:40 2120 0 全屏看文

AI助手支持GPT4.0

页面session失效,重新登录后返回提示页面路径不存在?The page session is invalid. After re-login, it returns to prompt that the page path does not exist?

页面session失效,重新登录后返回提示页面路径不存在?

我现在在我的资料页面(pages/my/data/index),然后清除服务器端的session,然后开发者工具编译请求接口,此时接口返回3002(session过期),小程序端判断是3002的话则跳转到登录页面(pages/login/index),登录成功后调用wx.navigateBack(),回到前一页。业务逻辑上没问题,但是回到我的资料页面的时候会调用onShow方法(我的获取资料接口请求是写在onReady里面的),我在onShow方法方法里面并没有写任何接口请求,所以页面是返回了但数据没有加载。如果在onShow里面也写了获取我的资料请求的话,页面进入的时候会调用两次,也就是会跳转两次到登录页面,此处不太合理。


重点来了我前一个页面的路径是pages/my/data/index,结果返回的时候却提示我页面路径不存在

WASubContext.js?t=wechat&s=1644839532374&v=2.21.4:2 pages/my/data/index: onShow have been invoked

WASubContext.js?t=wechat&s=1644839532374&v=2.21.4:2 Unhandled promise rejection {errMsg: "navigateTo:fail page "pages/my/data/" is not found"}


话说你这提示的页面路径也不是我的呀,我的最后是带index的


想问下怎么解决这个问题,感谢大佬


I am now in my data page (pages/my/data/index), then clear the session on the server side, then the developer tool compiles the request interface. At this time, the interface returns 3002 (session expires), and the small program ends up to 3002, then jumps to the login page (pages/login/ index), and calls wx. after successful login. Navigateback(), return to the previous page. There is no problem in business logic, but when I return to my data page, I will call Onshow method (my data acquisition interface request is written in onready). I did not write any interface request in Onshow method, so the page is returned but the data is not loaded. If the request for my information is also written in Onshow, it will be called twice when the page enters, that is, it will jump to the login page twice. This is not reasonable. The key point is that the path of my previous page is pages / my / data / index. When the result is returned, it prompts me that the page path does not exist wasubcontext js? t=wechat&s=1644839532374&v=2.21.4:2 pages/my/data/index: onShow have been invoked WASubContext. js? T = wechat & S = 164483952374 & v = 2.21.4:2 unhandled promise rejection {errmsg: "navigateto: fail page" pages / my / data / "is not found"} in other words, the page path you prompted is not mine. My last question is with index. I want to ask how to solve this problem. Thank you, boss

回答:

小面包🍞:

已经自行解决了,在登录页面的 onUnload方法中执行

var pages = getCurrentPages();

var prevPage = pages[pages.length - 2];  //上一个页面

prevPage.onLoad()

即可

八九:

代码呢

brave:话不多说,上代码片段

-EOF-

AI助手支持GPT4.0