Page Navigation
In a Mini Program, all page navigation is managed by the framework.
Page Stack
The framework maintains all current pages in a stack. When a route switch occurs, the page stack behaves as follows:
Routing Method | Page Stack Behavior |
---|---|
Initialization | New page is pushed onto the stack. |
Open New Page | New page is pushed onto the stack. |
Page Redirect | Current page is popped from the stack, and the new page is pushed onto the stack. |
Page Back | Pages are popped from the stack until the target return page is reached. |
Tab Switch | All pages are popped from the stack, leaving only the new Tab page. |
Page Reload | All pages are popped from the stack, leaving only the new page. |
Developers can use the getCurrentPages()
function to get the current page stack.
Routing Methods
For routing trigger methods and page lifecycle functions, refer to the following:
Routing Method | Triggering Occasion | Previous Page | Destination Page |
---|---|---|---|
Initialization | When the Mini Program is first opened. | onLoad , onShow | |
Open New Page | Using the dlt.navigateTo API. | onHide | onLoad , onShow |
Page Redirect | Using the dlt.redirectTo API. | onUnload | onLoad , onShow |
Page Back | Using the dlt.navigateBack API. User presses the upper-left back button. | onUnload | onShow |
Tab Switch | Using the dlt.switchTab API. User switches tabs. | Refer to the table below for various cases. | |
Relaunch | Using the dlt.reLaunch API. | onUnload | onLoad , onShow |
Tab Switch Corresponding Lifecycles (using A and B pages as Tabbar pages, C is opened from A, and D is opened from C):
Current Page | Destination Page | Triggered Lifecycles (in order) |
---|---|---|
A | A | Nothing happens |
A | B | A.onHide() , B.onLoad() , B.onShow() |
A | B (reopen) | 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 share) | A | D.onUnload() , A.onLoad() , A.onShow() |
D (from share) | B | D.onUnload() , B.onLoad() , B.onShow() |
Important Notes:
navigateTo
andredirectTo
can only open non-tabbar pages.switchTab
can only open tabbar pages.reLaunch
can open any page.- The bottom tabbar on a page is determined by that page, meaning any page defined as a tabbar page will have a bottom tabbar.
- Parameters passed via page routing can be retrieved in the
onLoad
of the destination page.