The routes for all pages in a Mini Program are managed by the framework.
The framework maintains all current pages in stack form. When route switching occurs, the page stack will behave as follows:
|Route method||Page stack behavior|
|Initialization||New page is stacked|
|Open new page||New page is stacked|
|Page redirect||Current page popped from stack, new page is stacked|
|Page back||Pages are continuously popped from stack until the target page is returned to, new pages are stacked|
|Tab switch||All pages are popped from stack with just a new tab page left behind|
|Reload||All pages are popped from stack with just a new page left behind|
The getCurrentPages() function is used to get an instance of the current page stack, which is given in array form in stack order. The first element is the homepage and the last element is the current page.
Tip: Do not try to modify the page stack, this will cause route and page status errors.
The route trigger methods and page lifecycle functions are as follows:
|Route method||When triggered||First page of route||Last page of route|
|Initialization||The first page of the Mini Program is opened||onLoad, onShow|
|Open new page||API
||Please refer to the following table for each situation|
Lifecycles corresponding to Tab switch (in the examples, pages A and B are the tab bar pages, C is a page opened from Page A, and page D is a page opened from page C):
|Current page||Last page of route||Trigger lifecycle (in order)|
|A||B||A.onHide(), B.onLoad(), B.onShow()|
|A||B (reopened)||A.onHide(), B.onShow()|
|C||B||C.onUnload(), B.onLoad(), B.onShow()|
|D||B||D.onUnload(), C.onUnload(), B.onLoad(), B.onShow()|
|D (entered from sharing)||A||D.onUnload(), A.onLoad(), A.onShow()|
|D (entered from sharing)||B||D.onUnload(), B.onLoad(), B.onShow()|
redirectTocan only open non-tab bar pages.
switchTabcan only open tab bar pages.
reLaunchcan open any page.
- The tab bar at the bottom of the page is determined by the page, that is, as long as a page is defined as a tab bar page, there will always be a tab bar at the bottom.
- The parameters brought when calling a page route can be obtained in
onLoadon the target page.