目录

Page Launch Mode

Defines the page launch behavior.

Static Declaration

You can add the launchMode attribute to router.page in the manifest file to declare the page launch mode.

Page Launch Mode Attribute

Attribute

Type

Default Value

Mandatory/Optional

Description

launchMode(1050+)

string

standard

Optional

Page launch mode. The options are singleTask and standard.

  • If this attribute is set to singleTask, the existing instance of the target page is opened each time a user opens the page, and the lifecycle function onRefresh is called back to delete pages opened through this page. If the target page has not opened before, a new instance is created for it.
  • If this attribute is set to standard, a new target page instance is created each time a user accesses the page. If a user accesses the page multiple times, multiple instances are created.

Sample code

"router": {
    "entry": "PageA",
    "pages": {
        "PageA": {
            "launchMode": "singleTask",
            "component": "index"
        },
        "PageB": {
            "launchMode": "standard",
            "component": "index"
        },
        "PageC": {
            "launchMode": "singleTask",
            "component": "index"
        }
    }
}

To open PageA, PageB, PageC, PageB, PageC, and PageA in sequence, perform the following operations:

  1. Open PageA. Before PageA is opened, the page stack is empty. When PageA is opened for the first time, the page stack consists of PageA.
  2. Open PageB. The launch mode of PageB is standard. That is, a PageB instance is created and displayed on PageA. The page stack consists of PageA and PageB.
  3. Open PageC. If PageC is opened for the first time, a PageC instance is created and displayed on PageB. The page stack consists of PageA, PageB, and PageC.
  4. Open PageB. The launch mode of PageB is standard. That is, a PageB instance is created and displayed on PageC. The page stack consists of PageA, PageB, PageC, and PageB.
  5. Open PageC. Since a PageC instance already exists, the PageB instance on PageC is closed, the existing PageC instance is displayed, and the onRefresh lifecycle function of PageC is called back. The page stack consists of PageA, PageB, and PageC.
  6. Open PageA. Since a PageA instance already exists, the PageB and PageC instances on PageA are closed, the existing PageA instance is displayed, and the onRefresh lifecycle function of PageA is called back. The page stack now consists of only PageA.

Dynamic Declaration

Two methods are available for dynamic declaration. One is to carry the launch flag attribute in router.push and the other is to carry the launch flag attribute in the link of the page to be opened. The launch flag attribute can control the page opening behavior.

Page Launch Flag Attribute

Attribute

Type

Mandatory/Optional

Description

___PARAM_LAUNCH_FLAG___

string

Optional

Page attribute passed for switching to a quick app page. If this attribute is set to clearTask, all other pages are closed when the target page is opened. If multiple instances of the target page exist, only the earliest instance is reserved and the onRefresh lifecycle function is called back. If no instance of the target page exists, all other pages are closed and an instance is created for the target page.

Sample code

// Set the page launch flag attribute to clearTask in the 1050+ version.
router.push({
    uri: '/PageB',
    params: {
        ___PARAM_LAUNCH_FLAG___: 'clearTask'
    }
})

If the page stack consists of PageA, PageB, and PageC in sequence and the page launch flag attribute is set to clearTask for PageB, the logic for opening PageB is as follows:

  1. Destroy the PageC instance.
  2. Destroy the PageA instance.
  3. Open the existing PageB instance and call back the onRefresh lifecycle function of PageB.

If the page stack consists of PageA and PageC in sequence and the page launch flag attribute is set to clearTask for PageB, the logic for opening PageB is as follows:

  1. Destroy the PageC instance.
  2. Destroy the PageA instance.
  3. Create a PageB instance and display it.

Links

[h2]Cases

Users Cannot Go Back to the Card by Tapping the Back Button from a Specified Page in a Quick App