2021-08-30 12:39:49 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020 Huawei Device Co., Ltd.
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2022-03-04 09:08:22 +00:00
|
|
|
* Defines the option of router.
|
2022-03-02 11:32:45 +00:00
|
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Lite
|
2022-03-04 09:08:22 +00:00
|
|
|
* @since 3
|
2021-08-30 12:39:49 +00:00
|
|
|
*/
|
|
|
|
export interface RouterOptions {
|
|
|
|
/**
|
|
|
|
* URI of the destination page, which supports the following formats:
|
|
|
|
* 1. Absolute path of the page, which is provided by the pages list in the config.json file.
|
|
|
|
* Example:
|
|
|
|
* pages/index/index
|
|
|
|
* pages/detail/detail
|
|
|
|
* 2. Particular path. If the URI is a slash (/), the home page is displayed.
|
2022-03-02 11:32:45 +00:00
|
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Lite
|
2021-08-30 12:39:49 +00:00
|
|
|
* @since 3
|
|
|
|
*/
|
|
|
|
uri: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Data that needs to be passed to the destination page during navigation.
|
|
|
|
* After the destination page is displayed, the parameter can be directly used for the page.
|
|
|
|
* For example, this.data1 (data1 is the key value of the params used for page navigation.)
|
2022-03-02 11:32:45 +00:00
|
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Lite
|
2021-08-30 12:39:49 +00:00
|
|
|
* @since 3
|
|
|
|
*/
|
|
|
|
params?: Object;
|
|
|
|
}
|
|
|
|
|
2021-10-18 07:45:23 +00:00
|
|
|
/**
|
2022-03-04 09:08:22 +00:00
|
|
|
* Defines the option of router back.
|
2022-03-02 11:32:45 +00:00
|
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Full
|
2022-03-04 09:08:22 +00:00
|
|
|
* @since 7
|
2021-10-18 07:45:23 +00:00
|
|
|
*/
|
|
|
|
export interface BackRouterOptions {
|
|
|
|
/**
|
|
|
|
* Returns to the page of the specified path.
|
|
|
|
* If the page with the specified path does not exist in the page stack, router.back() is called by default.
|
2022-03-02 11:32:45 +00:00
|
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Full
|
2021-10-18 07:45:23 +00:00
|
|
|
* @since 7
|
|
|
|
*/
|
|
|
|
uri?: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Data that needs to be passed to the destination page during navigation.
|
2022-03-02 11:32:45 +00:00
|
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Lite
|
2021-10-18 07:45:23 +00:00
|
|
|
* @since 7
|
|
|
|
*/
|
|
|
|
params?: Object;
|
|
|
|
}
|
|
|
|
|
2021-08-30 12:39:49 +00:00
|
|
|
/**
|
2022-03-04 09:08:22 +00:00
|
|
|
* Defines the state of router.
|
2022-03-02 11:32:45 +00:00
|
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Full
|
2022-03-04 09:08:22 +00:00
|
|
|
* @since 3
|
2021-08-30 12:39:49 +00:00
|
|
|
*/
|
|
|
|
export interface RouterState {
|
|
|
|
/**
|
|
|
|
* Index of the current page in the stack.
|
|
|
|
* NOTE: The index starts from 1 from the bottom to the top of the stack.
|
2022-03-02 11:32:45 +00:00
|
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Full
|
2021-08-30 12:39:49 +00:00
|
|
|
* @since 3
|
|
|
|
*/
|
|
|
|
index: number;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Name of the current page, that is, the file name.
|
2022-03-02 11:32:45 +00:00
|
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Full
|
2021-08-30 12:39:49 +00:00
|
|
|
* @since 3
|
|
|
|
*/
|
|
|
|
name: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Path of the current page.
|
2022-03-02 11:32:45 +00:00
|
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Full
|
2021-08-30 12:39:49 +00:00
|
|
|
* @since 3
|
|
|
|
*/
|
|
|
|
path: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-03-04 09:08:22 +00:00
|
|
|
* Defines the option of EnableAlertBeforeBackPage.
|
2022-03-02 11:32:45 +00:00
|
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Full
|
2022-03-04 09:08:22 +00:00
|
|
|
* @since 6
|
2021-08-30 12:39:49 +00:00
|
|
|
*/
|
|
|
|
export interface EnableAlertBeforeBackPageOptions {
|
|
|
|
/**
|
|
|
|
* dialog context.
|
2022-03-02 11:32:45 +00:00
|
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Full
|
2021-08-30 12:39:49 +00:00
|
|
|
* @since 6
|
|
|
|
*/
|
|
|
|
message: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the dialog box is displayed.
|
2022-03-02 11:32:45 +00:00
|
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Full
|
2021-08-30 12:39:49 +00:00
|
|
|
* @since 6
|
|
|
|
*/
|
|
|
|
success?: (errMsg: string) => void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the operation is cancelled.
|
2022-03-02 11:32:45 +00:00
|
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Full
|
2021-08-30 12:39:49 +00:00
|
|
|
* @since 6
|
|
|
|
*/
|
|
|
|
cancel?: (errMsg: string) => void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the dialog box is closed.
|
2022-03-02 11:32:45 +00:00
|
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Full
|
2021-08-30 12:39:49 +00:00
|
|
|
* @since 6
|
|
|
|
*/
|
|
|
|
complete?: () => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-03-04 09:08:22 +00:00
|
|
|
* Defines the option of DisableAlertBeforeBackPage.
|
2022-03-02 11:32:45 +00:00
|
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Full
|
2022-03-04 09:08:22 +00:00
|
|
|
* @since 6
|
2021-08-30 12:39:49 +00:00
|
|
|
*/
|
|
|
|
export interface DisableAlertBeforeBackPageOptions {
|
|
|
|
/**
|
|
|
|
* Called when the dialog box is displayed.
|
2022-03-02 11:32:45 +00:00
|
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Full
|
2021-08-30 12:39:49 +00:00
|
|
|
* @since 6
|
|
|
|
*/
|
|
|
|
success?: (errMsg: string) => void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the operation is cancelled.
|
2022-03-02 11:32:45 +00:00
|
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Full
|
2021-08-30 12:39:49 +00:00
|
|
|
* @since 6
|
|
|
|
*/
|
|
|
|
cancel?: (errMsg: string) => void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the dialog box is closed.
|
2022-03-02 11:32:45 +00:00
|
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Full
|
2021-08-30 12:39:49 +00:00
|
|
|
* @since 6
|
|
|
|
*/
|
|
|
|
complete?: () => void;
|
|
|
|
}
|
|
|
|
|
2022-03-16 02:39:37 +00:00
|
|
|
type ParamsInterface = {
|
|
|
|
[key: string]: Object;
|
|
|
|
};
|
|
|
|
|
2021-08-30 12:39:49 +00:00
|
|
|
/**
|
2022-03-04 09:08:22 +00:00
|
|
|
* Defines the Router interface.
|
2022-03-02 11:32:45 +00:00
|
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Lite
|
2022-03-04 09:08:22 +00:00
|
|
|
* @since 3
|
2021-08-30 12:39:49 +00:00
|
|
|
*/
|
|
|
|
export default class Router {
|
|
|
|
/**
|
|
|
|
* Navigates to a specified page in the application based on the page URL and parameters.
|
|
|
|
* @param options Options.
|
2022-03-02 11:32:45 +00:00
|
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Full
|
2022-03-04 09:08:22 +00:00
|
|
|
* @since 3
|
2021-08-30 12:39:49 +00:00
|
|
|
*/
|
|
|
|
static push(options: RouterOptions): void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Replaces the current page with another one in the application. The current page is destroyed after replacement.
|
2022-03-02 11:32:45 +00:00
|
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Lite
|
2021-08-30 12:39:49 +00:00
|
|
|
* @param options Options.
|
2022-03-04 09:08:22 +00:00
|
|
|
* @since 3
|
2021-08-30 12:39:49 +00:00
|
|
|
*/
|
|
|
|
static replace(options: RouterOptions): void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns to the previous page or a specified page.
|
2022-03-02 11:32:45 +00:00
|
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Full
|
2021-08-30 12:39:49 +00:00
|
|
|
* @param options Options.
|
2022-03-04 09:08:22 +00:00
|
|
|
* @since 3
|
2021-08-30 12:39:49 +00:00
|
|
|
*/
|
2021-10-18 07:45:23 +00:00
|
|
|
static back(options?: BackRouterOptions): void;
|
2021-08-30 12:39:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Obtains information about the current page params.
|
2022-03-02 11:32:45 +00:00
|
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Full
|
2021-08-30 12:39:49 +00:00
|
|
|
* @returns Page params.
|
|
|
|
* @since 7
|
|
|
|
*/
|
2022-03-16 02:39:37 +00:00
|
|
|
static getParams(): ParamsInterface;
|
2021-08-30 12:39:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Clears all historical pages and retains only the current page at the top of the stack.
|
2022-03-02 11:32:45 +00:00
|
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Full
|
2022-03-04 09:08:22 +00:00
|
|
|
* @since 3
|
2021-08-30 12:39:49 +00:00
|
|
|
*/
|
|
|
|
static clear(): void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Obtains the number of pages in the current stack.
|
|
|
|
* @returns Number of pages in the stack. The maximum value is 32.
|
2022-03-02 11:32:45 +00:00
|
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Full
|
2022-03-04 09:08:22 +00:00
|
|
|
* @since 3
|
2021-08-30 12:39:49 +00:00
|
|
|
*/
|
|
|
|
static getLength(): string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Obtains information about the current page state.
|
2022-03-02 11:32:45 +00:00
|
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Full
|
2021-08-30 12:39:49 +00:00
|
|
|
* @returns Page state.
|
2022-03-04 09:08:22 +00:00
|
|
|
* @since 3
|
2021-08-30 12:39:49 +00:00
|
|
|
*/
|
|
|
|
static getState(): RouterState;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pop up dialog to ask whether to back
|
2022-03-02 11:32:45 +00:00
|
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Full
|
2021-08-30 12:39:49 +00:00
|
|
|
* @param options Options.
|
2022-03-04 09:08:22 +00:00
|
|
|
* @since 6
|
2021-08-30 12:39:49 +00:00
|
|
|
*/
|
|
|
|
static enableAlertBeforeBackPage(options: EnableAlertBeforeBackPageOptions): void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* cancel enableAlertBeforeBackPage
|
2022-03-02 11:32:45 +00:00
|
|
|
* @syscap SystemCapability.ArkUI.ArkUI.Full
|
2021-08-30 12:39:49 +00:00
|
|
|
* @param options Options.
|
2022-03-04 09:08:22 +00:00
|
|
|
* @since 6
|
2021-08-30 12:39:49 +00:00
|
|
|
*/
|
|
|
|
static disableAlertBeforeBackPage(options?: DisableAlertBeforeBackPageOptions): void;
|
|
|
|
}
|