May 18, 2021 WeChat Mini Program Development Document
The route of all the pages in the applet is managed by the framework.
The frame maintains all the current pages in the form of a stack.When the routing is switched, the page stack behaves as follows:
Routing method | Page Stack Performance |
---|---|
initialization | New Page Inn |
Open a new page | New Page Inn |
Page redirection | Current page outlet, new page entry |
Page return | The page is constantly going out until the target returns to the page, the new page is in the stack |
Tab switching | The page is all in the stack, leaving only a new TAB page. |
Reload | All pages are out, leaving only new pages |
getCurrentPages()
The function is used to obtain an instance of the current page stack, given the order in the array form, the first element is the home page, the last element is the current page.
TIP: Don't try to modify the page stack, which causes routing and page status errors.
For the triggering method of the route, the page lifecycle function is as follows:
Routing method | Trigger | Routing front page | Routing |
---|---|---|---|
initialization | The first page opened by the small program | onLoad, onSHow | |
Open a new page |
Call API
wx.navigateTo
Or use the components
<navigator open-type="navigateTo"/>
|
onHide | onLoad, onShow |
Page redirection |
Call API
wx.redirectTo
Or use the components
<navigator open-type="redirectTo"/>
|
onUnload | onLoad, onShow |
Page return |
Call API
wx.navigateBack
Or use the components
<navigator open-type="navigateBack">
Or the user returns the button in the upper left corner
|
onUnload | onShow |
Tab switching |
Call API
wx.switchTab
Or use the components
<navigator open-type="switchTab"/>
Or user switches TAB
|
Please refer to the following table for a variety of situations. | |
Restart |
Call API
wx.reLaunch
Or use the components
<navigator open-type="reLaunch"/>
|
onUnload | onLoad, onShow |
Tab switching the corresponding lifecycle (with the A, B page for the Tabbar page, c is the page opened from the A page, the D page is the page opened from the C page as an example):
The current page | Routing | Triggering lifecycle (in order) |
---|---|---|
A | A | Nothing happend |
A | B | A.onHide(), B.onLoad(), B.onShow() |
A | B (open again) | A.onHide(), B.onShow() |
C | A | C.onUnload(), A.onShow() |
C | B | C.onUnload(), B.onLoad(), B.onShow() |
D | B | D.onUnload(), C.onUnload(), B.onLoad(), B.onShow() |
D (from forwarding into) | A | D.onUnload(), A.onLoad(), A.onShow() |
D (entry from forwarding) | B | D.onUnload(), B.onLoad(), B.onShow() |
Tips:
navigateTo
redirectTo
open non-tabBar pages.
switchTab
only open tabBar pages.
reLaunch
can open any page.
onLoad
the destination page.