WeChat applet customizes left back button event

The requirement of some projects is that a certain page returns to a specific page, which requires the operation of the back button of the page

 After reviewing the documentation and the community, several solutions were summarized

1. In the page life cycle callback function onUnload(), call wx.redirectTo() to close the current page and return to a certain page. But this method has a flaw, that is, the original default return page will appear first, and the page you want to return will appear later, and the user experience is not friendly enough.

2. Customize the return event by customizing the navigation bar. This method can only control the return button, but cannot control the user's physical return operation. It is too troublesome to monitor the user's physical return action and define the return event. (I will write this method when I have time later)

3. Open the return query dialog box through wx.enableAlertBeforeUnload(), but this method does not intercept when the gesture slides back, and now many people will not click the built-in return button when returning. wx.enableAlertBeforeUnload(Object object) | WeChat Open Documentation (qq.com)

4. Get rid of this requirement, the reason is that WeChat official currently does not provide an API to operate the back button.

At the beginning, I considered the way to operate the page stack, but the WeChat applet page stack can only be viewed through getCurrentPages(), and cannot be operated

Introduction to the page stack

PageObject[] getCurrentPages() | WeChat Open Documentation (qq.com)

Page Routing | WeChat Open Documentation (qq.com)

Guess you like

Origin blog.csdn.net/kxmzl/article/details/128116707