目录

Route and Lifecycle

In ASCF, the routes of all pages are managed by the framework.

Page Stack

The framework manages pages in the form of stacks. When a route switchover occurs, the corresponding page stack is as follows.

Routing Mode Page Stack
Initialization Pushes a new page onto the stack.
Opening a new page Pushes a new page onto the stack.
Redirecting to another page Pops the current page from the stack, and pushes a new page onto the stack.
Returning to a previous page Keeps popping pages from the stack until the target page is reached.
Switching tabs Pops all pages from the stack, leaving only the new tab.
Reloading a page Pops all pages from the stack, leaving only the new page.

You can use getCurrentPages() to obtain the current page stack.

Route and Page Lifecycle

The routing operation changes the page status and triggers the corresponding lifecycle. The table below lists several routing modes.

Routing Mode Called When Pre-routing Page Post-routing Page
Initialization The first page is opened by ASCF. - onLoad, onShow
Opening a new page The has.navigateTo API is called. onHide onLoad, onShow
Redirecting to another page The has.redirectTo API is called. onUnload onLoad, onShow
Returning to a previous page The has.navigateBack API is called, the component [/topic/body/section/table/tgroup/tbody/row/entry/b/navigator {""}) (navigator] is used, or the back button in the upper left corner is tapped. onUnload onShow
Switching tabs The has.switchTab API is called or a tab is tapped. - For details, see Lifecycle Triggered Upon Tab Switchover.
Reloading a page The has.reLaunch API is called. onUnload onLoad, onShow

Lifecycle Triggered Upon Tab Switchover

Assume that pages A and B are tab bar pages, page C is opened from page A, and page D is opened from page C.

Current Page Post-routing Page Lifecycle (Triggered in Sequence)
A A Nothing happened
A B A.onHide(), B.onLoad(), B.onShow()
A B (opened again) A.onHide(), B.onShow()
C A C.onUnload(), A.onShow()
C B C.onUnload(), B.onLoad(), B.onShow()
D B D.onUnload(), C.onUnload(), B.onLoad(), B.onShow()
D (opened from forwarding) A D.onUnload(), A.onLoad(), A.onShow()
D (opened from forwarding) B D.onUnload(), B.onLoad(), B.onShow()
  • navigateTo and redirectTo are used to open only non-tabBar pages.
  • switchTab is used to open only the tabBar page.
  • reLaunch is used to open any page.
  • If a page is defined as tabBar in the configuration file, a tab bar exists at the bottom of the page.

The parameters carried in the route of the called page can be obtained from onLoad of the target page.

The table below lists related APIs.

API Description
has.switchTab Switches between different tabs within the app. If an app defines multiple tabs, that is, there are tabs at the bottom or top of the client window, this API can be used to redirect to the tabBar page and close all other non-tabBar pages.
has.reLaunch Closes all current pages and opens an in-app page.
has.redirectTo Redirects to an in-app page while closing the current page. This API cannot navigate to the tabBar page.
has.navigateTo Navigates to a page within the app while retaining the current page. This API cannot navigate to the tabBar page. You can use has.navigateBack to return to the original page.
has.navigateBack Closes the current page and navigates back to the previous page or multiple levels up in the page stack.

For details about the parameters, see the API document.