The framework manages all the routes to pages of a Mini Program.
The framework maintains all the existing pages via stacks. When a route is switched, the page stack reacts as follows:
|Routing||Reaction on the Page Stack|
|Initialization||The new page is pushed onto the stack.|
|Opening a new page||The new page is pushed onto the stack.|
|Page redirection||The current page is popped out of the stack, and the new page is pushed onto the stack.|
|Page return||Pages are successively popped out of the stack until the destination return page is displayed.|
|Tab switching||All the pages are popped out of the stack, and only the new tab page is retained.|
|Reloading||All the pages are popped out of the stack, and only the new page is retained.|
Developers can obtain the current page stack by using the
The following shows how page routing is triggered and the lifecycle functions for pages.
|Routing||Trigger Condition||Source Page||Routed-To Page|
|Initialization||A page of the Mini Program is opened for the first time.||onLoad, onShow|
|Opening a new page||The API wx.navigateTo is called. |
|Page redirection||The API wx.redirectTo is called. |
|Page return||The API wx.navigateBack is called. |
The user taps the return button on the top left.
|Tab switching||The API wx.switchTab is called. |
The user switches between tabs.
|For details, refer to the following table.|
|Restart||The API wx.reLaunch is called. |
Lifecycle functions corresponding to tab switching (in the following example, pages A and B are Tabbar pages, page C is obtained after page A is opened, and page D is obtained after page C is opened):
|Current Page||Routed-To Page||Triggered Lifecycle Function (In Order)|
|A||B||A.onHide(), B.onLoad(), B.onShow()|
|A||B (Opened again)||A.onHide(), B.onShow()|
|C||B||C.onUnload(), B.onLoad(), B.onShow()|
|D||B||D.onUnload(), C.onUnload(), B.onLoad(), B.onShow()|
|D (Entered due to redirection)||A||D.onUnload(), A.onLoad(), A.onShow()|
|D (Entered due to redirection)||B||D.onUnload(), B.onLoad(), B.onShow()|
redirectTocan be used to open non-tabBar pages only.
switchTabcan be used to open tabBar pages only.
reLaunchcan be used to open any pages.
- The tabBar on the bottom of a page is determined by the page. In other words, tabBar is displayed on the bottom of all pages defined as tabBar.
- Parameters used to call page routing can be obtained via
onLoadin the destination page.