1/* 2 * Copyright (c) 2020 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16/** 17 * Defines the option of router. 18 * @syscap SystemCapability.ArkUI.ArkUI.Lite 19 * @deprecated since 8, please use @ohos.router instead. 20 * @since 3 21 */ 22export interface RouterOptions { 23 /** 24 * URI of the destination page, which supports the following formats: 25 * 1. Absolute path of the page, which is provided by the pages list in the config.json file. 26 * Example: 27 * pages/index/index 28 * pages/detail/detail 29 * 2. Particular path. If the URI is a slash (/), the home page is displayed. 30 * @syscap SystemCapability.ArkUI.ArkUI.Lite 31 * @since 3 32 */ 33 uri: string; 34 35 /** 36 * Data that needs to be passed to the destination page during navigation. 37 * After the destination page is displayed, the parameter can be directly used for the page. 38 * For example, this.data1 (data1 is the key value of the params used for page navigation.) 39 * @syscap SystemCapability.ArkUI.ArkUI.Lite 40 * @since 3 41 */ 42 params?: Object; 43} 44 45/** 46 * Defines the option of router back. 47 * @syscap SystemCapability.ArkUI.ArkUI.Full 48 * @deprecated since 8, please use @ohos.router instead. 49 * @since 7 50 */ 51export interface BackRouterOptions { 52 /** 53 * Returns to the page of the specified path. 54 * If the page with the specified path does not exist in the page stack, router.back() is called by default. 55 * @syscap SystemCapability.ArkUI.ArkUI.Full 56 * @since 7 57 */ 58 uri?: string; 59 60 /** 61 * Data that needs to be passed to the destination page during navigation. 62 * @syscap SystemCapability.ArkUI.ArkUI.Lite 63 * @since 7 64 */ 65 params?: Object; 66} 67 68/** 69 * Defines the state of router. 70 * @syscap SystemCapability.ArkUI.ArkUI.Full 71 * @deprecated since 8, please use @ohos.router instead. 72 * @since 3 73 */ 74export interface RouterState { 75 /** 76 * Index of the current page in the stack. 77 * NOTE: The index starts from 1 from the bottom to the top of the stack. 78 * @syscap SystemCapability.ArkUI.ArkUI.Full 79 * @since 3 80 */ 81 index: number; 82 83 /** 84 * Name of the current page, that is, the file name. 85 * @syscap SystemCapability.ArkUI.ArkUI.Full 86 * @since 3 87 */ 88 name: string; 89 90 /** 91 * Path of the current page. 92 * @syscap SystemCapability.ArkUI.ArkUI.Full 93 * @since 3 94 */ 95 path: string; 96} 97 98/** 99 * Defines the option of EnableAlertBeforeBackPage. 100 * @syscap SystemCapability.ArkUI.ArkUI.Full 101 * @deprecated since 8, please use @ohos.router instead. 102 * @since 6 103 */ 104export interface EnableAlertBeforeBackPageOptions { 105 /** 106 * dialog context. 107 * @syscap SystemCapability.ArkUI.ArkUI.Full 108 * @since 6 109 */ 110 message: string; 111 112 /** 113 * Called when the dialog box is displayed. 114 * @syscap SystemCapability.ArkUI.ArkUI.Full 115 * @since 6 116 */ 117 success?: (errMsg: string) => void; 118 119 /** 120 * Called when the operation is cancelled. 121 * @syscap SystemCapability.ArkUI.ArkUI.Full 122 * @since 6 123 */ 124 cancel?: (errMsg: string) => void; 125 126 /** 127 * Called when the dialog box is closed. 128 * @syscap SystemCapability.ArkUI.ArkUI.Full 129 * @since 6 130 */ 131 complete?: () => void; 132} 133 134/** 135 * Defines the option of DisableAlertBeforeBackPage. 136 * @syscap SystemCapability.ArkUI.ArkUI.Full 137 * @deprecated since 8, please use @ohos.router instead. 138 * @since 6 139 */ 140export interface DisableAlertBeforeBackPageOptions { 141 /** 142 * Called when the dialog box is displayed. 143 * @syscap SystemCapability.ArkUI.ArkUI.Full 144 * @since 6 145 */ 146 success?: (errMsg: string) => void; 147 148 /** 149 * Called when the operation is cancelled. 150 * @syscap SystemCapability.ArkUI.ArkUI.Full 151 * @since 6 152 */ 153 cancel?: (errMsg: string) => void; 154 155 /** 156 * Called when the dialog box is closed. 157 * @syscap SystemCapability.ArkUI.ArkUI.Full 158 * @since 6 159 */ 160 complete?: () => void; 161} 162 163type ParamsInterface = { 164 [key: string]: Object; 165}; 166 167/** 168 * Defines the Router interface. 169 * @syscap SystemCapability.ArkUI.ArkUI.Lite 170 * @deprecated since 8, please use @ohos.router instead. 171 * @since 3 172 */ 173export default class Router { 174 /** 175 * Navigates to a specified page in the application based on the page URL and parameters. 176 * @param options Options. 177 * @syscap SystemCapability.ArkUI.ArkUI.Full 178 * @since 3 179 */ 180 static push(options: RouterOptions): void; 181 182 /** 183 * Replaces the current page with another one in the application. The current page is destroyed after replacement. 184 * @syscap SystemCapability.ArkUI.ArkUI.Lite 185 * @param options Options. 186 * @since 3 187 */ 188 static replace(options: RouterOptions): void; 189 190 /** 191 * Returns to the previous page or a specified page. 192 * @syscap SystemCapability.ArkUI.ArkUI.Full 193 * @param options Options. 194 * @since 3 195 */ 196 static back(options?: BackRouterOptions): void; 197 198 /** 199 * Obtains information about the current page params. 200 * @syscap SystemCapability.ArkUI.ArkUI.Full 201 * @returns Page params. 202 * @since 7 203 */ 204 static getParams(): ParamsInterface; 205 206 /** 207 * Clears all historical pages and retains only the current page at the top of the stack. 208 * @syscap SystemCapability.ArkUI.ArkUI.Full 209 * @since 3 210 */ 211 static clear(): void; 212 213 /** 214 * Obtains the number of pages in the current stack. 215 * @returns Number of pages in the stack. The maximum value is 32. 216 * @syscap SystemCapability.ArkUI.ArkUI.Full 217 * @since 3 218 */ 219 static getLength(): string; 220 221 /** 222 * Obtains information about the current page state. 223 * @syscap SystemCapability.ArkUI.ArkUI.Full 224 * @returns Page state. 225 * @since 3 226 */ 227 static getState(): RouterState; 228 229 /** 230 * Pop up dialog to ask whether to back 231 * @syscap SystemCapability.ArkUI.ArkUI.Full 232 * @param options Options. 233 * @since 6 234 */ 235 static enableAlertBeforeBackPage(options: EnableAlertBeforeBackPageOptions): void; 236 237 /** 238 * cancel enableAlertBeforeBackPage 239 * @syscap SystemCapability.ArkUI.ArkUI.Full 240 * @param options Options. 241 * @since 6 242 */ 243 static disableAlertBeforeBackPage(options?: DisableAlertBeforeBackPageOptions): void; 244} 245