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 * @file 18 * @kit ArkUI 19 */ 20 21/** 22 * Defines the option of router. 23 * 24 * @interface RouterOptions 25 * @syscap SystemCapability.ArkUI.ArkUI.Lite 26 * @since 3 27 * @deprecated since 8 28 * @useinstead ohos.router#RouterOptions 29 */ 30export interface RouterOptions { 31 /** 32 * URI of the destination page, which supports the following formats: 33 * 1. Absolute path of the page, which is provided by the pages list in the config.json file. 34 * Example: 35 * pages/index/index 36 * pages/detail/detail 37 * 2. Particular path. If the URI is a slash (/), the home page is displayed. 38 * 39 * @type { string } 40 * @syscap SystemCapability.ArkUI.ArkUI.Lite 41 * @since 3 42 * @deprecated since 8 43 */ 44 uri: string; 45 46 /** 47 * Data that needs to be passed to the destination page during navigation. 48 * After the destination page is displayed, the parameter can be directly used for the page. 49 * For example, this.data1 (data1 is the key value of the params used for page navigation.) 50 * 51 * @type { ?Object } 52 * @syscap SystemCapability.ArkUI.ArkUI.Lite 53 * @since 3 54 * @deprecated since 8 55 */ 56 params?: Object; 57} 58 59/** 60 * Defines the option of router back. 61 * 62 * @interface BackRouterOptions 63 * @syscap SystemCapability.ArkUI.ArkUI.Full 64 * @since 7 65 * @deprecated since 8 66 * @useinstead ohos.router#RouterOptions 67 */ 68export interface BackRouterOptions { 69 /** 70 * Returns to the page of the specified path. 71 * If the page with the specified path does not exist in the page stack, router.back() is called by default. 72 * 73 * @type { ?string } 74 * @syscap SystemCapability.ArkUI.ArkUI.Full 75 * @since 7 76 * @deprecated since 8 77 */ 78 uri?: string; 79 80 /** 81 * Data that needs to be passed to the destination page during navigation. 82 * 83 * @type { ?Object } 84 * @syscap SystemCapability.ArkUI.ArkUI.Lite 85 * @since 7 86 * @deprecated since 8 87 */ 88 params?: Object; 89} 90 91/** 92 * Defines the state of router. 93 * 94 * @interface RouterState 95 * @syscap SystemCapability.ArkUI.ArkUI.Full 96 * @since 3 97 * @deprecated since 8 98 * @useinstead ohos.router#RouterState 99 */ 100export interface RouterState { 101 /** 102 * Index of the current page in the stack. 103 * NOTE: The index starts from 1 from the bottom to the top of the stack. 104 * 105 * @type { number } 106 * @syscap SystemCapability.ArkUI.ArkUI.Full 107 * @since 3 108 * @deprecated since 8 109 */ 110 index: number; 111 112 /** 113 * Name of the current page, that is, the file name. 114 * 115 * @type { string } 116 * @syscap SystemCapability.ArkUI.ArkUI.Full 117 * @since 3 118 * @deprecated since 8 119 */ 120 name: string; 121 122 /** 123 * Path of the current page. 124 * 125 * @type { string } 126 * @syscap SystemCapability.ArkUI.ArkUI.Full 127 * @since 3 128 * @deprecated since 8 129 */ 130 path: string; 131} 132 133/** 134 * Defines the option of EnableAlertBeforeBackPage. 135 * 136 * @interface EnableAlertBeforeBackPageOptions 137 * @syscap SystemCapability.ArkUI.ArkUI.Full 138 * @since 6 139 * @deprecated since 8 140 * @useinstead ohos.router#RouterState 141 */ 142export interface EnableAlertBeforeBackPageOptions { 143 /** 144 * dialog context. 145 * 146 * @type { string } 147 * @syscap SystemCapability.ArkUI.ArkUI.Full 148 * @since 6 149 * @deprecated since 8 150 */ 151 message: string; 152 153 /** 154 * Called when the dialog box is displayed. 155 * 156 * @type { ?function } 157 * @syscap SystemCapability.ArkUI.ArkUI.Full 158 * @since 6 159 * @deprecated since 8 160 */ 161 success?: (errMsg: string) => void; 162 163 /** 164 * Called when the operation is cancelled. 165 * 166 * @type { ?function } 167 * @syscap SystemCapability.ArkUI.ArkUI.Full 168 * @since 6 169 * @deprecated since 8 170 */ 171 cancel?: (errMsg: string) => void; 172 173 /** 174 * Called when the dialog box is closed. 175 * 176 * @type { ?function } 177 * @syscap SystemCapability.ArkUI.ArkUI.Full 178 * @since 6 179 * @deprecated since 8 180 */ 181 complete?: () => void; 182} 183 184/** 185 * Defines the option of DisableAlertBeforeBackPage. 186 * 187 * @interface DisableAlertBeforeBackPageOptions 188 * @syscap SystemCapability.ArkUI.ArkUI.Full 189 * @since 6 190 * @deprecated since 8 191 * @useinstead ohos.router#RouterOptions 192 */ 193export interface DisableAlertBeforeBackPageOptions { 194 /** 195 * Called when the dialog box is displayed. 196 * 197 * @type { ?function } 198 * @syscap SystemCapability.ArkUI.ArkUI.Full 199 * @since 6 200 * @deprecated since 8 201 */ 202 success?: (errMsg: string) => void; 203 204 /** 205 * Called when the operation is cancelled. 206 * 207 * @type { ?function } 208 * @syscap SystemCapability.ArkUI.ArkUI.Full 209 * @since 6 210 * @deprecated since 8 211 */ 212 cancel?: (errMsg: string) => void; 213 214 /** 215 * Called when the dialog box is closed. 216 * 217 * @type { ?function } 218 * @syscap SystemCapability.ArkUI.ArkUI.Full 219 * @since 6 220 * @deprecated since 8 221 */ 222 complete?: () => void; 223} 224 225/** 226 * Define ParamsInterface. 227 * 228 * @syscap SystemCapability.ArkUI.ArkUI.Full 229 * @since 7 230 * @deprecated since 8 231 */ 232type ParamsInterface = { 233 [key: string]: Object; 234}; 235 236/** 237 * Defines the Router interface. 238 * 239 * @syscap SystemCapability.ArkUI.ArkUI.Lite 240 * @since 3 241 * @deprecated since 8 242 * @useinstead ohos.router#router 243 */ 244export default class Router { 245 /** 246 * Navigates to a specified page in the application based on the page URL and parameters. 247 * 248 * @param { RouterOptions } options Options. 249 * @syscap SystemCapability.ArkUI.ArkUI.Full 250 * @since 3 251 * @deprecated since 8 252 */ 253 static push(options: RouterOptions): void; 254 255 /** 256 * Replaces the current page with another one in the application. The current page is destroyed after replacement. 257 * 258 * @param { RouterOptions } options Options. 259 * @syscap SystemCapability.ArkUI.ArkUI.Lite 260 * @since 3 261 * @deprecated since 8 262 */ 263 static replace(options: RouterOptions): void; 264 265 /** 266 * Returns to the previous page or a specified page. 267 * 268 * @param { BackRouterOptions } options Options. 269 * @syscap SystemCapability.ArkUI.ArkUI.Full 270 * @since 3 271 * @deprecated since 8 272 */ 273 static back(options?: BackRouterOptions): void; 274 275 /** 276 * Obtains information about the current page params. 277 * 278 * @returns { ParamsInterface } Page params. 279 * @syscap SystemCapability.ArkUI.ArkUI.Full 280 * @since 7 281 * @deprecated since 8 282 */ 283 static getParams(): ParamsInterface; 284 285 /** 286 * Clears all historical pages and retains only the current page at the top of the stack. 287 * 288 * @syscap SystemCapability.ArkUI.ArkUI.Full 289 * @since 3 290 * @deprecated since 8 291 */ 292 static clear(): void; 293 294 /** 295 * Obtains the number of pages in the current stack. 296 * 297 * @returns { string } Number of pages in the stack. The maximum value is 32. 298 * @syscap SystemCapability.ArkUI.ArkUI.Full 299 * @since 3 300 * @deprecated since 8 301 */ 302 static getLength(): string; 303 304 /** 305 * Obtains information about the current page state. 306 * 307 * @returns { RouterState } Page state. 308 * @syscap SystemCapability.ArkUI.ArkUI.Full 309 * @since 3 310 * @deprecated since 8 311 */ 312 static getState(): RouterState; 313 314 /** 315 * Pop up dialog to ask whether to back 316 * 317 * @param { EnableAlertBeforeBackPageOptions } options Options. 318 * @syscap SystemCapability.ArkUI.ArkUI.Full 319 * @since 6 320 * @deprecated since 8 321 */ 322 static enableAlertBeforeBackPage(options: EnableAlertBeforeBackPageOptions): void; 323 324 /** 325 * cancel enableAlertBeforeBackPage 326 * 327 * @param { DisableAlertBeforeBackPageOptions } options Options. 328 * @syscap SystemCapability.ArkUI.ArkUI.Full 329 * @since 6 330 * @deprecated since 8 331 */ 332 static disableAlertBeforeBackPage(options?: DisableAlertBeforeBackPageOptions): void; 333} 334