• 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 * @devices tv, phone, tablet, wearable, liteWearable, smartVision
18 */
19export interface RouterOptions {
20  /**
21   * URI of the destination page, which supports the following formats:
22   * 1. Absolute path of the page, which is provided by the pages list in the config.json file.
23   *    Example:
24   *      pages/index/index
25   *      pages/detail/detail
26   * 2. Particular path. If the URI is a slash (/), the home page is displayed.
27   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
28   * @since 3
29   */
30  uri: string;
31
32  /**
33   * Data that needs to be passed to the destination page during navigation.
34   * After the destination page is displayed, the parameter can be directly used for the page.
35   * For example, this.data1 (data1 is the key value of the params used for page navigation.)
36   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
37   * @since 3
38   */
39  params?: Object;
40}
41
42/**
43 * @devices tv, phone, tablet, wearable
44 */
45export interface RouterState {
46  /**
47   * Index of the current page in the stack.
48   * NOTE: The index starts from 1 from the bottom to the top of the stack.
49   * @devices tv, phone, tablet, wearable
50   * @since 3
51   */
52  index: number;
53
54  /**
55   * Name of the current page, that is, the file name.
56   * @devices tv, phone, tablet, wearable
57   * @since 3
58   */
59  name: string;
60
61  /**
62   * Path of the current page.
63   * @devices tv, phone, tablet, wearable
64   * @since 3
65   */
66  path: string;
67}
68
69/**
70 * @devices phone, tablet
71 */
72export interface EnableAlertBeforeBackPageOptions {
73  /**
74   * dialog context.
75   * @devices phone, tablet
76   * @since 6
77   */
78  message: string;
79
80  /**
81   * Called when the dialog box is displayed.
82   * @devices phone, tablet
83   * @since 6
84   */
85  success?: (errMsg: string) => void;
86
87  /**
88   * Called when the operation is cancelled.
89   * @devices phone, tablet
90   * @since 6
91   */
92  cancel?: (errMsg: string) => void;
93
94  /**
95   * Called when the dialog box is closed.
96   * @devices phone, tablet
97   * @since 6
98   */
99  complete?: () => void;
100}
101
102/**
103 * @devices phone, tablet
104 */
105export interface DisableAlertBeforeBackPageOptions {
106  /**
107   * Called when the dialog box is displayed.
108   * @devices phone, tablet
109   * @since 6
110   */
111  success?: (errMsg: string) => void;
112
113  /**
114   * Called when the operation is cancelled.
115   * @devices phone, tablet
116   * @since 6
117   */
118  cancel?: (errMsg: string) => void;
119
120  /**
121   * Called when the dialog box is closed.
122   * @devices phone, tablet
123   * @since 6
124   */
125  complete?: () => void;
126}
127
128/**
129 * @devices tv, phone, tablet, wearable, liteWearable, smartVision
130 */
131export default class Router {
132  /**
133   * Navigates to a specified page in the application based on the page URL and parameters.
134   * @param options Options.
135   * @devices tv, phone, tablet, wearable
136   */
137  static push(options: RouterOptions): void;
138
139  /**
140   * Replaces the current page with another one in the application. The current page is destroyed after replacement.
141   * @param options Options.
142   * @devices tv, phone, tablet, wearable, liteWearable, smartVision
143   */
144  static replace(options: RouterOptions): void;
145
146  /**
147   * Returns to the previous page or a specified page.
148   * @param options Options.
149   * @devices tv, phone, tablet, wearable
150   * @since 7
151   */
152  static back(options?: RouterOptions): void;
153
154  /**
155   * Obtains information about the current page params.
156   * @returns Page params.
157   * @devices tv, phone, tablet, wearable
158   * @since 7
159   */
160  static getParams(): Object;
161
162  /**
163   * Clears all historical pages and retains only the current page at the top of the stack.
164   * @devices tv, phone, tablet, wearable
165   */
166  static clear(): void;
167
168  /**
169   * Obtains the number of pages in the current stack.
170   * @returns Number of pages in the stack. The maximum value is 32.
171   * @devices tv, phone, tablet, wearable
172   */
173  static getLength(): string;
174
175  /**
176   * Obtains information about the current page state.
177   * @returns Page state.
178   * @devices tv, phone, tablet, wearable
179   */
180  static getState(): RouterState;
181
182  /**
183   * Pop up dialog to ask whether to back
184   * @param options Options.
185   * @devices phone, tablet
186   */
187  static enableAlertBeforeBackPage(options: EnableAlertBeforeBackPageOptions): void;
188
189  /**
190   * cancel enableAlertBeforeBackPage
191   * @param options Options.
192   * @devices phone, tablet
193   */
194  static disableAlertBeforeBackPage(options?: DisableAlertBeforeBackPageOptions): void;
195}
196