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