• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021 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
16import {Callback} from './basic';
17
18/**
19 * @syscap SystemCapability.ArkUI.ArkUI.Full
20 * @since 8
21 * @import router from '@ohos.router';
22 */
23declare namespace router {
24
25  /**
26   * @since 8
27   */
28  interface RouterOptions {
29
30    /**
31     * URI of the destination page, which supports the following formats:
32     * 1. Absolute path of the page, which is provided by the pages list in the config.json file.
33     *    Example:
34     *      pages/index/index
35     *      pages/detail/detail
36     * 2. Particular path. If the URI is a slash (/), the home page is displayed.
37     * @syscap SystemCapability.ArkUI.ArkUI.Lite
38     * @since 8
39     */
40    url: string;
41
42    /**
43     * Data that needs to be passed to the destination page during navigation.
44     * After the destination page is displayed, the parameter can be directly used for the page.
45     * For example, this.data1 (data1 is the key value of the params used for page navigation.)
46     * @syscap SystemCapability.ArkUI.ArkUI.Lite
47     * @since 8
48     */
49    params?: Object;
50  }
51
52  /**
53   * @since 8
54   */
55  interface RouterState {
56
57    /**
58     * Index of the current page in the stack.
59     * NOTE: The index starts from 1 from the bottom to the top of the stack.
60     * @since 8
61     */
62    index: number;
63
64    /**
65     * Name of the current page, that is, the file name.
66     * @since 8
67     */
68    name: string;
69
70    /**
71     * Path of the current page.
72     * @since 8
73     */
74    path: string;
75  }
76
77  /**
78   * @since 8
79   */
80  interface EnableAlertOptions {
81
82    /**
83     * dialog context.
84     * @since 8
85     */
86    message: string;
87  }
88
89  /**
90   * Navigates to a specified page in the application based on the page URL and parameters.
91   * @param options Options.
92   * @since 8
93   */
94  function push(options: RouterOptions):void;
95
96  /**
97   * Replaces the current page with another one in the application. The current page is destroyed after replacement.
98   * @param options Options.
99   * @since 8
100   */
101  function replace(options: RouterOptions):void;
102
103  /**
104   * Returns to the previous page or a specified page.
105   * @param options Options.
106   * @since 8
107   */
108  function back(options?: RouterOptions ):void;
109
110  /**
111   * Clears all historical pages and retains only the current page at the top of the stack.
112   * @since 8
113   */
114  function clear():void;
115
116  /**
117   * Obtains the number of pages in the current stack.
118   * @returns Number of pages in the stack. The maximum value is 32.
119   * @since 8
120   */
121  function getLength():string;
122
123  /**
124   * Obtains information about the current page state.
125   * @returns Page state.
126   * @since 8
127   */
128  function getState():RouterState;
129
130  /**
131   * Pop up dialog to ask whether to back
132   * @param options Options.
133   * @since 8
134   */
135  function enableAlertBeforeBackPage(options: EnableAlertOptions):void;
136
137  /**
138   * cancel enableAlertBeforeBackPage
139   * @since 8
140   */
141  function disableAlertBeforeBackPage():void;
142
143  /**
144   * Obtains information about the current page params.
145   * @returns Page params.
146   * @since 8
147   */
148  function getParams(): Object;
149}
150
151export default router;
152