1 | /**
|
2 | *
|
3 | * original code from: https://github.com/qiu8310/minapp/blob/master/packages/minapp-wx/typing/wx.d.ts
|
4 | * Lincenced under MIT license: https://github.com/qiu8310/minapp/issues/69
|
5 | * thanks for the great work by @qiu8310 👍👍👍
|
6 | *
|
7 | */
|
8 | declare namespace Router {
|
9 | namespace navigateTo {
|
10 | type Param = {
|
11 | /**
|
12 | * 需要跳转的应用内非 tabBar 的页面的路径 , 路径后可以带参数。参数与路径之间使用`?`分隔,参数键与参数值用`=`相连,不同参数用`&`分隔;如 'path?key=value&key2=value2'
|
13 | */
|
14 | url: string
|
15 | /**
|
16 | * 接口调用成功的回调函数
|
17 | */
|
18 | success?: ParamPropSuccess
|
19 | /**
|
20 | * 接口调用失败的回调函数
|
21 | */
|
22 | fail?: ParamPropFail
|
23 | /**
|
24 | * 接口调用结束的回调函数(调用成功、失败都会执行)
|
25 | */
|
26 | complete?: ParamPropComplete
|
27 | }
|
28 | /**
|
29 | * 接口调用成功的回调函数
|
30 | */
|
31 | type ParamPropSuccess = (res: any) => any
|
32 | /**
|
33 | * 接口调用失败的回调函数
|
34 | */
|
35 | type ParamPropFail = (err: any) => any
|
36 | /**
|
37 | * 接口调用结束的回调函数(调用成功、失败都会执行)
|
38 | */
|
39 | type ParamPropComplete = () => any
|
40 | }
|
41 | /**
|
42 | * 保留当前页面,跳转到应用内的某个页面,使用`Router.navigateBack`可以返回到原页面。
|
43 | *
|
44 | * **示例代码:**
|
45 | *
|
46 | * ```javascript
|
47 | * Router.navigateTo({
|
48 | * url: 'test?id=1'
|
49 | * })
|
50 | * ```
|
51 | *
|
52 | * **示例代码:**
|
53 | *
|
54 | * ```javascript
|
55 | * //test.js
|
56 | * Page({
|
57 | * onLoad: function(option){
|
58 | * console.log(option.query)
|
59 | * }
|
60 | * })
|
61 | * ```
|
62 | * @see https://developers.weixin.qq.com/miniprogram/dev/api/ui-navigate.html#wxnavigatetoobject
|
63 | */
|
64 | function navigateTo(OBJECT: navigateTo.Param): void
|
65 |
|
66 | namespace redirectTo {
|
67 | type Param = {
|
68 | /**
|
69 | * 需要跳转的应用内非 tabBar 的页面的路径,路径后可以带参数。参数与路径之间使用`?`分隔,参数键与参数值用`=`相连,不同参数用`&`分隔;如 'path?key=value&key2=value2'
|
70 | */
|
71 | url: string
|
72 | /**
|
73 | * 接口调用成功的回调函数
|
74 | */
|
75 | success?: ParamPropSuccess
|
76 | /**
|
77 | * 接口调用失败的回调函数
|
78 | */
|
79 | fail?: ParamPropFail
|
80 | /**
|
81 | * 接口调用结束的回调函数(调用成功、失败都会执行)
|
82 | */
|
83 | complete?: ParamPropComplete
|
84 | }
|
85 | /**
|
86 | * 接口调用成功的回调函数
|
87 | */
|
88 | type ParamPropSuccess = (res: any) => any
|
89 | /**
|
90 | * 接口调用失败的回调函数
|
91 | */
|
92 | type ParamPropFail = (err: any) => any
|
93 | /**
|
94 | * 接口调用结束的回调函数(调用成功、失败都会执行)
|
95 | */
|
96 | type ParamPropComplete = () => any
|
97 | }
|
98 | /**
|
99 | * 关闭当前页面,跳转到应用内的某个页面。
|
100 | *
|
101 | * **示例代码:**
|
102 | *
|
103 | * ```javascript
|
104 | * Router.redirectTo({
|
105 | * url: 'test?id=1'
|
106 | * })
|
107 | * ```
|
108 | * @see https://developers.weixin.qq.com/miniprogram/dev/api/ui-navigate.html#wxredirecttoobject
|
109 | */
|
110 | function redirectTo(OBJECT: redirectTo.Param): void
|
111 |
|
112 | namespace reLaunch {
|
113 | type Param = {
|
114 | /**
|
115 | * 需要跳转的应用内页面路径 , 路径后可以带参数。参数与路径之间使用`?`分隔,参数键与参数值用`=`相连,不同参数用`&`分隔;如 'path?key=value&key2=value2',如果跳转的页面路径是 tabBar 页面则不能带参数
|
116 | */
|
117 | url: string
|
118 | /**
|
119 | * 接口调用成功的回调函数
|
120 | */
|
121 | success?: ParamPropSuccess
|
122 | /**
|
123 | * 接口调用失败的回调函数
|
124 | */
|
125 | fail?: ParamPropFail
|
126 | /**
|
127 | * 接口调用结束的回调函数(调用成功、失败都会执行)
|
128 | */
|
129 | complete?: ParamPropComplete
|
130 | }
|
131 | /**
|
132 | * 接口调用成功的回调函数
|
133 | */
|
134 | type ParamPropSuccess = (res: any) => any
|
135 | /**
|
136 | * 接口调用失败的回调函数
|
137 | */
|
138 | type ParamPropFail = (err: any) => any
|
139 | /**
|
140 | * 接口调用结束的回调函数(调用成功、失败都会执行)
|
141 | */
|
142 | type ParamPropComplete = () => any
|
143 | }
|
144 | /**
|
145 | * @since 1.1.0
|
146 | *
|
147 | * 关闭所有页面,打开到应用内的某个页面。
|
148 | *
|
149 | * **示例代码:**
|
150 | *
|
151 | * ```javascript
|
152 | * Router.reLaunch({
|
153 | * url: 'test?id=1'
|
154 | * })
|
155 | * ```
|
156 | *
|
157 | * **示例代码:**
|
158 | *
|
159 | * ```javascript
|
160 | * //test.js
|
161 | * Page({
|
162 | * onLoad: function(option){
|
163 | * console.log(option.query)
|
164 | * }
|
165 | * })
|
166 | * ```
|
167 | * @see https://developers.weixin.qq.com/miniprogram/dev/api/ui-navigate.html#wxrelaunchobject
|
168 | */
|
169 | function reLaunch(OBJECT: reLaunch.Param): void
|
170 |
|
171 | namespace switchTab {
|
172 | type Param = {
|
173 | /**
|
174 | * 需要跳转的 tabBar 页面的路径(需在 app.json 的 [tabBar](https://developers.weixin.qq.com/miniprogram/dev/framework/config.html#tabbar) 字段定义的页面),路径后不能带参数
|
175 | */
|
176 | url: string
|
177 | /**
|
178 | * 接口调用成功的回调函数
|
179 | */
|
180 | success?: ParamPropSuccess
|
181 | /**
|
182 | * 接口调用失败的回调函数
|
183 | */
|
184 | fail?: ParamPropFail
|
185 | /**
|
186 | * 接口调用结束的回调函数(调用成功、失败都会执行)
|
187 | */
|
188 | complete?: ParamPropComplete
|
189 | }
|
190 | /**
|
191 | * 接口调用成功的回调函数
|
192 | */
|
193 | type ParamPropSuccess = (res: any) => any
|
194 | /**
|
195 | * 接口调用失败的回调函数
|
196 | */
|
197 | type ParamPropFail = (err: any) => any
|
198 | /**
|
199 | * 接口调用结束的回调函数(调用成功、失败都会执行)
|
200 | */
|
201 | type ParamPropComplete = () => any
|
202 | }
|
203 | /**
|
204 | * 跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面
|
205 | *
|
206 | * **示例代码:**
|
207 | *
|
208 | * ```json
|
209 | * {
|
210 | * "tabBar": {
|
211 | * "list": [{
|
212 | * "pagePath": "index",
|
213 | * "text": "首页"
|
214 | * },{
|
215 | * "pagePath": "other",
|
216 | * "text": "其他"
|
217 | * }]
|
218 | * }
|
219 | * }
|
220 | * ```
|
221 | *
|
222 | * **示例代码:**
|
223 | *
|
224 | * ```javascript
|
225 | * Router.switchTab({
|
226 | * url: '/index'
|
227 | * })
|
228 | * ```
|
229 | * @see https://developers.weixin.qq.com/miniprogram/dev/api/ui-navigate.html#wxswitchtabobject
|
230 | */
|
231 | function switchTab(OBJECT: switchTab.Param): void
|
232 |
|
233 | namespace navigateBack {
|
234 | type Param = {
|
235 | /**
|
236 | * 返回的页面数,如果 delta 大于现有页面数,则返回到首页。
|
237 | *
|
238 | * @default 1
|
239 | */
|
240 | delta?: number
|
241 | }
|
242 | }
|
243 | /**
|
244 | * 关闭当前页面,返回上一页面或多级页面。可通过 [`getCurrentPages()`](https://developers.weixin.qq.com/miniprogram/dev/framework/app-service/page.html#getCurrentPages()) 获取当前的页面栈,决定需要返回几层。
|
245 | *
|
246 | * **Tip:**
|
247 | *
|
248 | * 1. `tip`: Router.navigateTo 和 Router.redirectTo 不允许跳转到 tabbar 页面,只能用 Router.switchTab 跳转到 tabbar 页面
|
249 | *
|
250 | * **示例代码:**
|
251 | *
|
252 | * ```javascript
|
253 | * // 注意:调用 navigateTo 跳转时,调用该方法的页面会被加入堆栈,而 redirectTo 方法则不会。见下方示例代码
|
254 | *
|
255 | * // 此处是A页面
|
256 | * Router.navigateTo({
|
257 | * url: 'B?id=1'
|
258 | * })
|
259 | *
|
260 | * // 此处是B页面
|
261 | * Router.navigateTo({
|
262 | * url: 'C?id=1'
|
263 | * })
|
264 | *
|
265 | * // 在C页面内 navigateBack,将返回A页面
|
266 | * Router.navigateBack({
|
267 | * delta: 2
|
268 | * })
|
269 | * ```
|
270 | * @see https://developers.weixin.qq.com/miniprogram/dev/api/ui-navigate.html#wxnavigatebackobject
|
271 | */
|
272 | function navigateBack(OBJECT: navigateBack.Param): void
|
273 | }
|
274 |
|
275 | declare const createHistory: (props: {
|
276 | basename?: string;
|
277 | mode: 'hash' | 'browser',
|
278 | firstPagePath: string;
|
279 | customRoutes: {
|
280 | [key: string]: string | string[]
|
281 | };
|
282 | }) => any;
|
283 |
|
284 | export {
|
285 | Router,
|
286 | createHistory
|
287 | }
|