Use getCurrentPages()
method to obtain instances of the current page stack and return the page array stack. The first element is the homepage, the last element is the current page.
The framework maintains all the current pages in the form of stacks. The following table shows the relationship between routing switch and page stack:
Routing mode | Page stack performance |
---|---|
Initialize | Push a new page |
Open a new page | Push a new page |
Redirect a page | Pop the current page, push a new page |
Return to a page | Pop the current page |
Switch Tab | Pop all pages, only leave the new Tab page |
You can use the following code snippet to detect whether the current page stack has a five-level page depth.
if(getCurrentPages().length === 5) {
my.redirectTo('/pages/logs/logs');
} else {
my.navigateTo('/pages/index/index');
}
Note: Do not try to change the page stack, otherwise, it will cause routing and page status errors.