WeChat Mini Program Learning Road "Seven" page routing

WeChat Mini Program Development - Page Routing

 

 

Page routing actually refers to the page access path when the user operates the applet, for example: from page1 to page2 to page3 to page4 and then back to page2, page1..., then page1 -> page2 -> page3 -> page4 -> The path of page2 -> page1... can be called the page routing of the applet.

 

The applet framework also maintains all pages accessed by the user in the form of stacks, which are called page stacks. When a route switch (page change) occurs, the page stack behaves differently.

 

Let's integrate page routing, page life cycle, and page stack together, and have a deep understanding of the implementation principle of page framework.



 
Then, according to the above page routing and page stack, look at the change process of the top element of the page stack.



 

getCurrentPages()

getCurrentPages() The function is used to get an instance of the current page stack, which is given in the order of the stack in the form of an array, the first element is the home page, and the last element is the current page.

 

Print the page routing through the function and view the routing log

 

var rout = getCurrentPages()
console.log(rout)
console.log(rout[0].__route__)
Note: Do not try to modify the page stack, it will cause routing and page status errors.     wx.navigateBack

Close the current page and return to the previous page or multi-level page. By  getCurrentPages()getting the current page stack, you can decide how many layers you need to return.

wx.navigateBack({

  delta: getCurrentPages().length-1 // return the number of pages, if the delta is greater than the number of existing pages, return to the home page

})

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327037115&siteId=291194637