How many ways does the applet jump to the page? Any difference?


How many ways does the applet jump to the page?

In the applet, each page can be regarded as a pagemodel, which is managed in the form of stack (up to five layers)

Before we talk about jump mode, let’s review the difference between stack and heap

Different management methods

Stack is the system compiler startup management, which does not need to be managed manually by programmers
Heap release is manually managed by the programmer. If it is not collected in time, it is easy to cause memory leakage

Different distribution methods

There are two allocation methods for stack: static allocation and dynamic allocation
Static allocation is done by the system compiler, such as the allocation of local variables
Dynamic allocation is allocated by the alloc function, but the dynamic allocation of stack is different from that of heap. Its dynamic allocation is also released by the system compiler and does not need to be manually managed by programmers
Heap is dynamically allocated and reclaimed memory, and there is no statically allocated heap

Different allocation sizes

Stack is a data structure extending to low address, which is a continuous memory area
Heap is a data structure extending to high address, which is a discontinuous memory area

Get to the point

There are two types of route jumps for applets, component jumps and API jumps

API forms are divided into

Navigateto keeps the current page, jumps to a page in the application, and returns to the original page using wx.navigateback
Redirectto closes the current page and jumps to a page in the application
Switchtab jumps to the tabbar page and closes other non tabbar pages
Navigateback returns to the previous page
Relanch closes all pages and opens to a page in the application
Stack was mentioned earlier. What is the relationship between these navigation methods and stack? See below

Initialize new page stack
Navigateto new page stack
Redirectto: the current page goes out of the stack and the new page goes into the stack
The navigateback page keeps coming out of the stack until the target page returns and the new page is put into the stack
All switchtab pages are out of the stack, leaving only new tab pages
Relanch pages are all out of the stack, leaving only new pages
Jump through components

//The default open type of the navigator component is navigate

Jump to new page

//If you need to jump in other forms, you can change the API value above the open type attribute

Toggle tab

Getcurrentpages() function is used to obtain the instance (property and method) of the current page stack, which is given in the order of stack in the form of array. The first element is the home page and the last element is the current page

//Page a jumps to page B
wx.navigateTo({ url: ‘/pages/B/B’ })

// Page B
const pages = getCurrentPages()
Const perpage = pages [pages. Length – 2] / / previous page
Title: ‘JS daily question’
Applet pages are managed in stack form, up to 5 layers, and jump in a reasonable way in a reasonable scenario

This work adoptsCC agreement, reprint must indicate the author and the link to this article