@tarojs/router 3.5.0-alpha.1 → 3.5.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +938 -4
- package/dist/index.js.map +1 -0
- package/dist/{index.cjs.js → router.esm.js} +41 -57
- package/dist/router.esm.js.map +1 -0
- package/package.json +9 -9
- package/dist/animation.js +0 -29
- package/dist/api.js +0 -91
- package/dist/events/resize.js +0 -13
- package/dist/events/scroll.js +0 -30
- package/dist/history.js +0 -99
- package/dist/index.cjs.js.map +0 -1
- package/dist/router/index.js +0 -23
- package/dist/router/mpa.js +0 -49
- package/dist/router/multi-page.js +0 -105
- package/dist/router/page.js +0 -265
- package/dist/router/spa.js +0 -110
- package/dist/router/stack.js +0 -57
- package/dist/tabbar.js +0 -29
- package/dist/utils.js +0 -39
package/dist/index.js
CHANGED
|
@@ -1,4 +1,938 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var history = require('history');
|
|
6
|
+
var runtime = require('@tarojs/runtime');
|
|
7
|
+
var UniversalRouter = require('universal-router');
|
|
8
|
+
var queryString = require('query-string');
|
|
9
|
+
var taro = require('@tarojs/taro');
|
|
10
|
+
|
|
11
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
12
|
+
|
|
13
|
+
var UniversalRouter__default = /*#__PURE__*/_interopDefaultLegacy(UniversalRouter);
|
|
14
|
+
var queryString__default = /*#__PURE__*/_interopDefaultLegacy(queryString);
|
|
15
|
+
|
|
16
|
+
const addLeadingSlash = (url = '') => (url.charAt(0) === '/' ? url : '/' + url);
|
|
17
|
+
const hasBasename = (path = '', prefix = '') => new RegExp('^' + prefix + '(\\/|\\?|#|$)', 'i').test(path) || path === prefix;
|
|
18
|
+
const stripBasename = (path = '', prefix = '') => hasBasename(path, prefix) ? path.substr(prefix.length) : path;
|
|
19
|
+
class RoutesAlias {
|
|
20
|
+
conf = [];
|
|
21
|
+
set(customRoutes = {}) {
|
|
22
|
+
for (let key in customRoutes) {
|
|
23
|
+
const path = customRoutes[key];
|
|
24
|
+
key = addLeadingSlash(key);
|
|
25
|
+
if (typeof path === 'string') {
|
|
26
|
+
this.conf.push([key, addLeadingSlash(path)]);
|
|
27
|
+
}
|
|
28
|
+
else if (path?.length > 0) {
|
|
29
|
+
this.conf.push(...path.map(p => [key, addLeadingSlash(p)]));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
getConfig = (url = '') => {
|
|
34
|
+
const customRoute = this.conf.filter((arr) => {
|
|
35
|
+
return arr.includes(url);
|
|
36
|
+
});
|
|
37
|
+
return customRoute[0];
|
|
38
|
+
};
|
|
39
|
+
getOrigin = (url = '') => {
|
|
40
|
+
return this.getConfig(url)?.[0] || url;
|
|
41
|
+
};
|
|
42
|
+
getAlias = (url = '') => {
|
|
43
|
+
return this.getConfig(url)?.[1] || url;
|
|
44
|
+
};
|
|
45
|
+
getAll = (url = '') => {
|
|
46
|
+
return this.conf
|
|
47
|
+
.filter((arr) => arr.includes(url))
|
|
48
|
+
.reduceRight((p, a) => {
|
|
49
|
+
p.unshift(a[1]);
|
|
50
|
+
return p;
|
|
51
|
+
}, []);
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
const routesAlias = new RoutesAlias();
|
|
55
|
+
|
|
56
|
+
class RouterConfig {
|
|
57
|
+
static __config;
|
|
58
|
+
static set config(e) {
|
|
59
|
+
this.__config = e;
|
|
60
|
+
}
|
|
61
|
+
static get config() {
|
|
62
|
+
return this.__config;
|
|
63
|
+
}
|
|
64
|
+
static get pages() {
|
|
65
|
+
return this.config.pages || [];
|
|
66
|
+
}
|
|
67
|
+
static get router() {
|
|
68
|
+
return this.config.router || {};
|
|
69
|
+
}
|
|
70
|
+
static get mode() {
|
|
71
|
+
return this.router.mode || 'hash';
|
|
72
|
+
}
|
|
73
|
+
static get customRoutes() { return this.router.customRoutes || {}; }
|
|
74
|
+
static isPage(url = '') {
|
|
75
|
+
return this.pages.findIndex(e => addLeadingSlash(e) === url) !== -1;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
exports.history = void 0;
|
|
80
|
+
let basename = '/';
|
|
81
|
+
class MpaHistory {
|
|
82
|
+
action;
|
|
83
|
+
get location() {
|
|
84
|
+
return {
|
|
85
|
+
pathname: window.location.pathname,
|
|
86
|
+
search: window.location.search,
|
|
87
|
+
hash: window.location.hash,
|
|
88
|
+
key: `${window.history.length}`,
|
|
89
|
+
state: window.history.state
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
createHref(_to) {
|
|
93
|
+
throw new Error('Method not implemented.');
|
|
94
|
+
}
|
|
95
|
+
parseUrl(to) {
|
|
96
|
+
let url = to.pathname || '';
|
|
97
|
+
if (RouterConfig.isPage(url)) {
|
|
98
|
+
url += '.html';
|
|
99
|
+
}
|
|
100
|
+
if (to.search) {
|
|
101
|
+
url += `?${to.search}`;
|
|
102
|
+
}
|
|
103
|
+
if (to.hash) {
|
|
104
|
+
url += `#${to.hash}`;
|
|
105
|
+
}
|
|
106
|
+
return url;
|
|
107
|
+
}
|
|
108
|
+
push(to, _state = {}) {
|
|
109
|
+
window.location.pathname = this.parseUrl(to);
|
|
110
|
+
// this.pushState(_state, '', this.parseUrl(to))
|
|
111
|
+
}
|
|
112
|
+
replace(to, _state = {}) {
|
|
113
|
+
window.location.replace(this.parseUrl(to));
|
|
114
|
+
// this.replaceState(_state, '', this.parseUrl(to))
|
|
115
|
+
}
|
|
116
|
+
go(delta) {
|
|
117
|
+
window.history.go(delta);
|
|
118
|
+
}
|
|
119
|
+
back = window.history.back;
|
|
120
|
+
forward = window.history.forward;
|
|
121
|
+
listen(listener) {
|
|
122
|
+
function callback(e) {
|
|
123
|
+
if (e.action === 'pushState') {
|
|
124
|
+
listener({ action: history.Action.Push, location: this.location });
|
|
125
|
+
}
|
|
126
|
+
else if (e.action === 'replaceState') {
|
|
127
|
+
listener({ action: history.Action.Replace, location: this.location });
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
// NOTE: 这里包括 back、forward、go 三种可能,并非是 POP 事件
|
|
131
|
+
listener({ action: history.Action.Pop, location: this.location });
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
window.addEventListener('popstate', callback);
|
|
135
|
+
return () => {
|
|
136
|
+
window.removeEventListener('popstate', callback);
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
block(_blocker) {
|
|
140
|
+
throw new Error('Method not implemented.');
|
|
141
|
+
}
|
|
142
|
+
pushState = this.eventState('pushState');
|
|
143
|
+
replaceState = this.eventState('replaceState');
|
|
144
|
+
eventState(action) {
|
|
145
|
+
return (data, unused, url) => {
|
|
146
|
+
const wrapper = window.history[action](data, unused, url);
|
|
147
|
+
const evt = new Event(action);
|
|
148
|
+
evt.action = action;
|
|
149
|
+
evt.state = data;
|
|
150
|
+
evt.unused = unused;
|
|
151
|
+
evt.url = url;
|
|
152
|
+
window.dispatchEvent(evt);
|
|
153
|
+
return wrapper;
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
function setHistoryMode(mode, base = '/') {
|
|
158
|
+
const options = {
|
|
159
|
+
window
|
|
160
|
+
};
|
|
161
|
+
basename = base;
|
|
162
|
+
if (mode === 'browser') {
|
|
163
|
+
exports.history = history.createBrowserHistory(options);
|
|
164
|
+
}
|
|
165
|
+
else if (mode === 'multi') {
|
|
166
|
+
exports.history = new MpaHistory();
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
// default is hash
|
|
170
|
+
exports.history = history.createHashHistory(options);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
function prependBasename(url = '') {
|
|
174
|
+
return basename.replace(/\/$/, '') + '/' + url.replace(/^\//, '');
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
class Stacks {
|
|
178
|
+
stacks = [];
|
|
179
|
+
backDelta = 0;
|
|
180
|
+
set delta(delta) {
|
|
181
|
+
if (delta > 0) {
|
|
182
|
+
this.backDelta = delta;
|
|
183
|
+
}
|
|
184
|
+
else if (this.backDelta > 0) {
|
|
185
|
+
--this.backDelta;
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
this.backDelta = 0;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
get delta() {
|
|
192
|
+
return this.backDelta;
|
|
193
|
+
}
|
|
194
|
+
get length() {
|
|
195
|
+
return this.stacks.length;
|
|
196
|
+
}
|
|
197
|
+
get last() {
|
|
198
|
+
return this.stacks[this.length - 1];
|
|
199
|
+
}
|
|
200
|
+
get() {
|
|
201
|
+
return this.stacks;
|
|
202
|
+
}
|
|
203
|
+
getItem(index) {
|
|
204
|
+
return this.stacks[index];
|
|
205
|
+
}
|
|
206
|
+
getLastIndex(pathname, stateWith = 1) {
|
|
207
|
+
const list = [...this.stacks].reverse();
|
|
208
|
+
return list.findIndex((page, i) => i >= stateWith && page.path?.replace(/\?.*/g, '') === pathname);
|
|
209
|
+
}
|
|
210
|
+
getDelta(pathname) {
|
|
211
|
+
if (this.backDelta >= 1) {
|
|
212
|
+
return this.backDelta;
|
|
213
|
+
}
|
|
214
|
+
const index = this.getLastIndex(pathname);
|
|
215
|
+
// NOTE: 此处为了修复浏览器后退多级页面,在大量重复路由状况下可能出现判断错误的情况 (增强判断能力只能考虑在 query 中新增参数来判断,暂时搁置)
|
|
216
|
+
return index > 0 ? index : 1;
|
|
217
|
+
}
|
|
218
|
+
getPrevIndex(pathname, stateWith = 1) {
|
|
219
|
+
const lastIndex = this.getLastIndex(pathname, stateWith);
|
|
220
|
+
if (lastIndex < 0) {
|
|
221
|
+
return -1;
|
|
222
|
+
}
|
|
223
|
+
return this.length - 1 - lastIndex;
|
|
224
|
+
}
|
|
225
|
+
pop() {
|
|
226
|
+
return this.stacks.pop();
|
|
227
|
+
}
|
|
228
|
+
push(page) {
|
|
229
|
+
return this.stacks.push(page);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
const stacks = new Stacks();
|
|
233
|
+
|
|
234
|
+
function processNavigateUrl(option) {
|
|
235
|
+
const pathPieces = history.parsePath(option.url);
|
|
236
|
+
// 处理相对路径
|
|
237
|
+
if (pathPieces.pathname?.includes('./')) {
|
|
238
|
+
const parts = routesAlias.getOrigin(exports.history.location.pathname).split('/');
|
|
239
|
+
parts.pop();
|
|
240
|
+
pathPieces.pathname.split('/').forEach((item) => {
|
|
241
|
+
if (item === '.') {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
item === '..' ? parts.pop() : parts.push(item);
|
|
245
|
+
});
|
|
246
|
+
pathPieces.pathname = parts.join('/');
|
|
247
|
+
}
|
|
248
|
+
// 处理自定义路由
|
|
249
|
+
pathPieces.pathname = routesAlias.getAlias(addLeadingSlash(pathPieces.pathname));
|
|
250
|
+
// 处理 basename
|
|
251
|
+
pathPieces.pathname = prependBasename(pathPieces.pathname);
|
|
252
|
+
// hack fix history v5 bug: https://github.com/remix-run/history/issues/814
|
|
253
|
+
if (!pathPieces.search)
|
|
254
|
+
pathPieces.search = '';
|
|
255
|
+
return pathPieces;
|
|
256
|
+
}
|
|
257
|
+
async function navigate(option, method) {
|
|
258
|
+
return new Promise((resolve, reject) => {
|
|
259
|
+
const { success, complete, fail } = option;
|
|
260
|
+
const unListen = exports.history.listen(() => {
|
|
261
|
+
const res = { errMsg: `${method}:ok` };
|
|
262
|
+
success?.(res);
|
|
263
|
+
complete?.(res);
|
|
264
|
+
resolve(res);
|
|
265
|
+
unListen();
|
|
266
|
+
});
|
|
267
|
+
try {
|
|
268
|
+
if ('url' in option) {
|
|
269
|
+
const pathPieces = processNavigateUrl(option);
|
|
270
|
+
const state = { timestamp: Date.now() };
|
|
271
|
+
if (method === 'navigateTo') {
|
|
272
|
+
exports.history.push(pathPieces, state);
|
|
273
|
+
}
|
|
274
|
+
else if (method === 'redirectTo' || method === 'switchTab') {
|
|
275
|
+
exports.history.replace(pathPieces, state);
|
|
276
|
+
}
|
|
277
|
+
else if (method === 'reLaunch') {
|
|
278
|
+
stacks.delta = stacks.length;
|
|
279
|
+
exports.history.replace(pathPieces, state);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
else if (method === 'navigateBack') {
|
|
283
|
+
stacks.delta = option.delta;
|
|
284
|
+
exports.history.go(-option.delta);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
catch (error) {
|
|
288
|
+
const res = { errMsg: `${method}:fail ${error.message || error}` };
|
|
289
|
+
fail?.(res);
|
|
290
|
+
complete?.(res);
|
|
291
|
+
reject(res);
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
function navigateTo(option) {
|
|
296
|
+
return navigate(option, 'navigateTo');
|
|
297
|
+
}
|
|
298
|
+
function redirectTo(option) {
|
|
299
|
+
return navigate(option, 'redirectTo');
|
|
300
|
+
}
|
|
301
|
+
function navigateBack(option = { delta: 1 }) {
|
|
302
|
+
if (!option.delta || option.delta < 1) {
|
|
303
|
+
option.delta = 1;
|
|
304
|
+
}
|
|
305
|
+
return navigate(option, 'navigateBack');
|
|
306
|
+
}
|
|
307
|
+
function switchTab(option) {
|
|
308
|
+
return navigate(option, 'switchTab');
|
|
309
|
+
}
|
|
310
|
+
function reLaunch(option) {
|
|
311
|
+
return navigate(option, 'reLaunch');
|
|
312
|
+
}
|
|
313
|
+
function getCurrentPages() {
|
|
314
|
+
if (process.env.NODE_ENV === 'development' && RouterConfig.mode === 'multi') {
|
|
315
|
+
console.warn('多页面路由模式不支持使用 getCurrentPages 方法!');
|
|
316
|
+
}
|
|
317
|
+
const pages = stacks.get();
|
|
318
|
+
return pages.map(e => ({ ...e, route: e.path || '' }));
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* 插入页面动画需要的样式
|
|
323
|
+
*/
|
|
324
|
+
function loadAnimateStyle(ms = 300) {
|
|
325
|
+
const css = `
|
|
326
|
+
.taro_router .taro_page {
|
|
327
|
+
position: absolute;
|
|
328
|
+
left: 0;
|
|
329
|
+
top: 0;
|
|
330
|
+
width: 100%;
|
|
331
|
+
height: 100%;
|
|
332
|
+
background-color: #fff;
|
|
333
|
+
transform: translate(100%, 0);
|
|
334
|
+
transition: transform ${ms}ms;
|
|
335
|
+
z-index: 0;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
.taro_router .taro_page.taro_tabbar_page,
|
|
339
|
+
.taro_router .taro_page.taro_page_show.taro_page_stationed {
|
|
340
|
+
transform: none;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
.taro_router .taro_page.taro_page_show {
|
|
344
|
+
transform: translate(0, 0);
|
|
345
|
+
}`;
|
|
346
|
+
const style = document.createElement('style');
|
|
347
|
+
style.innerHTML = css;
|
|
348
|
+
document.getElementsByTagName('head')[0].appendChild(style);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
let pageResizeFn;
|
|
352
|
+
function bindPageResize(page) {
|
|
353
|
+
pageResizeFn && window.removeEventListener('resize', pageResizeFn);
|
|
354
|
+
pageResizeFn = function () {
|
|
355
|
+
page.onResize && page.onResize({
|
|
356
|
+
size: {
|
|
357
|
+
windowHeight: window.innerHeight,
|
|
358
|
+
windowWidth: window.innerWidth
|
|
359
|
+
}
|
|
360
|
+
});
|
|
361
|
+
};
|
|
362
|
+
window.addEventListener('resize', pageResizeFn, false);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
let pageScrollFn;
|
|
366
|
+
let pageDOM = window;
|
|
367
|
+
function bindPageScroll(page, pageEl, distance = 50) {
|
|
368
|
+
pageScrollFn && pageEl.removeEventListener('scroll', pageScrollFn);
|
|
369
|
+
pageDOM = pageEl;
|
|
370
|
+
let isReachBottom = false;
|
|
371
|
+
pageScrollFn = function () {
|
|
372
|
+
page.onPageScroll && page.onPageScroll({
|
|
373
|
+
scrollTop: pageDOM instanceof Window ? window.scrollY : pageDOM.scrollTop
|
|
374
|
+
});
|
|
375
|
+
if (isReachBottom && getOffset() > distance) {
|
|
376
|
+
isReachBottom = false;
|
|
377
|
+
}
|
|
378
|
+
if (page.onReachBottom &&
|
|
379
|
+
!isReachBottom &&
|
|
380
|
+
getOffset() < distance) {
|
|
381
|
+
isReachBottom = true;
|
|
382
|
+
page.onReachBottom();
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
pageDOM.addEventListener('scroll', pageScrollFn, false);
|
|
386
|
+
}
|
|
387
|
+
function getOffset() {
|
|
388
|
+
if (pageDOM instanceof Window) {
|
|
389
|
+
return document.documentElement.scrollHeight - window.scrollY - window.innerHeight;
|
|
390
|
+
}
|
|
391
|
+
else {
|
|
392
|
+
return pageDOM.scrollHeight - pageDOM.scrollTop - pageDOM.clientHeight;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// @ts-nocheck
|
|
397
|
+
function initTabbar(config) {
|
|
398
|
+
if (config.tabBar == null) {
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
// TODO: custom-tab-bar
|
|
402
|
+
const tabbar = document.createElement('taro-tabbar');
|
|
403
|
+
const homePage = config.entryPagePath || (config.pages ? config.pages[0] : '');
|
|
404
|
+
tabbar.conf = config.tabBar;
|
|
405
|
+
tabbar.conf.homePage = exports.history.location.pathname === '/' ? homePage : exports.history.location.pathname;
|
|
406
|
+
const routerConfig = config.router;
|
|
407
|
+
tabbar.conf.mode = routerConfig && routerConfig.mode ? routerConfig.mode : 'hash';
|
|
408
|
+
if (routerConfig.customRoutes) {
|
|
409
|
+
tabbar.conf.custom = true;
|
|
410
|
+
tabbar.conf.customRoutes = routerConfig.customRoutes;
|
|
411
|
+
}
|
|
412
|
+
else {
|
|
413
|
+
tabbar.conf.custom = false;
|
|
414
|
+
tabbar.conf.customRoutes = {};
|
|
415
|
+
}
|
|
416
|
+
if (typeof routerConfig.basename !== 'undefined') {
|
|
417
|
+
tabbar.conf.basename = routerConfig.basename;
|
|
418
|
+
}
|
|
419
|
+
const container = document.getElementById('container');
|
|
420
|
+
container?.appendChild(tabbar);
|
|
421
|
+
taro.initTabBarApis(config);
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
function setDisplay(el, type = '') {
|
|
425
|
+
if (el) {
|
|
426
|
+
el.style.display = type;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
class PageHandler {
|
|
430
|
+
config;
|
|
431
|
+
defaultAnimation = { duration: 300, delay: 50 };
|
|
432
|
+
unloadTimer;
|
|
433
|
+
hideTimer;
|
|
434
|
+
lastHidePage;
|
|
435
|
+
lastUnloadPage;
|
|
436
|
+
constructor(config) {
|
|
437
|
+
this.config = config;
|
|
438
|
+
this.mount();
|
|
439
|
+
}
|
|
440
|
+
get appId() { return 'app'; }
|
|
441
|
+
get router() { return this.config.router; }
|
|
442
|
+
get routerMode() { return this.router.mode || 'hash'; }
|
|
443
|
+
get customRoutes() { return this.router.customRoutes || {}; }
|
|
444
|
+
get routes() { return this.config.routes; }
|
|
445
|
+
get tabBarList() { return this.config.tabBar?.list || []; }
|
|
446
|
+
get PullDownRefresh() { return this.config.PullDownRefresh; }
|
|
447
|
+
get animation() { return this.config?.animation ?? this.defaultAnimation; }
|
|
448
|
+
get animationDelay() {
|
|
449
|
+
return (typeof this.animation === 'object'
|
|
450
|
+
? this.animation.delay
|
|
451
|
+
: this.animation
|
|
452
|
+
? this.defaultAnimation?.delay
|
|
453
|
+
: 0) || 0;
|
|
454
|
+
}
|
|
455
|
+
get animationDuration() {
|
|
456
|
+
return (typeof this.animation === 'object'
|
|
457
|
+
? this.animation.duration
|
|
458
|
+
: this.animation
|
|
459
|
+
? this.defaultAnimation?.duration
|
|
460
|
+
: 0) || 0;
|
|
461
|
+
}
|
|
462
|
+
set pathname(p) { this.router.pathname = p; }
|
|
463
|
+
get pathname() { return this.router.pathname; }
|
|
464
|
+
get basename() { return this.router.basename || ''; }
|
|
465
|
+
get pageConfig() {
|
|
466
|
+
return this.routes.find(r => {
|
|
467
|
+
const routePath = stripBasename(this.pathname, this.basename);
|
|
468
|
+
const pagePath = addLeadingSlash(r.path);
|
|
469
|
+
return pagePath === routePath || routesAlias.getConfig(pagePath)?.includes(routePath);
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
get isTabBar() {
|
|
473
|
+
const routePath = stripBasename(this.pathname, this.basename);
|
|
474
|
+
const pagePath = Object.entries(this.customRoutes).find(([, target]) => {
|
|
475
|
+
if (typeof target === 'string') {
|
|
476
|
+
return target === routePath;
|
|
477
|
+
}
|
|
478
|
+
else if (target?.length > 0) {
|
|
479
|
+
return target.includes(routePath);
|
|
480
|
+
}
|
|
481
|
+
return false;
|
|
482
|
+
})?.[0] || routePath;
|
|
483
|
+
return !!pagePath && this.tabBarList.some(t => t.pagePath === pagePath);
|
|
484
|
+
}
|
|
485
|
+
isSamePage(page) {
|
|
486
|
+
const routePath = stripBasename(this.pathname, this.basename);
|
|
487
|
+
const pagePath = stripBasename(page?.path, this.basename);
|
|
488
|
+
return pagePath.startsWith(routePath + '?');
|
|
489
|
+
}
|
|
490
|
+
get search() {
|
|
491
|
+
let search = '?';
|
|
492
|
+
if (this.routerMode === 'hash') {
|
|
493
|
+
const idx = location.hash.indexOf('?');
|
|
494
|
+
if (idx > -1) {
|
|
495
|
+
search = location.hash.slice(idx);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
else {
|
|
499
|
+
search = location.search;
|
|
500
|
+
}
|
|
501
|
+
return search.substr(1);
|
|
502
|
+
}
|
|
503
|
+
getQuery(stamp = 0, search = '', options = {}) {
|
|
504
|
+
search = search ? `${search}&${this.search}` : this.search;
|
|
505
|
+
const query = search
|
|
506
|
+
? queryString__default["default"].parse(search, { decode: false })
|
|
507
|
+
: {};
|
|
508
|
+
query.stamp = stamp.toString();
|
|
509
|
+
return { ...query, ...options };
|
|
510
|
+
}
|
|
511
|
+
mount() {
|
|
512
|
+
setHistoryMode(this.routerMode, this.router.basename);
|
|
513
|
+
document.getElementById('app')?.remove();
|
|
514
|
+
this.animation && loadAnimateStyle(this.animationDuration);
|
|
515
|
+
const app = document.createElement('div');
|
|
516
|
+
app.id = this.appId;
|
|
517
|
+
app.classList.add('taro_router');
|
|
518
|
+
if (this.tabBarList.length > 1) {
|
|
519
|
+
const container = document.createElement('div');
|
|
520
|
+
container.classList.add('taro-tabbar__container');
|
|
521
|
+
container.id = 'container';
|
|
522
|
+
const panel = document.createElement('div');
|
|
523
|
+
panel.classList.add('taro-tabbar__panel');
|
|
524
|
+
panel.appendChild(app);
|
|
525
|
+
container.appendChild(panel);
|
|
526
|
+
document.body.appendChild(container);
|
|
527
|
+
initTabbar(this.config);
|
|
528
|
+
}
|
|
529
|
+
else {
|
|
530
|
+
document.body.appendChild(app);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
onReady(page, onLoad = true) {
|
|
534
|
+
const pageEl = this.getPageContainer(page);
|
|
535
|
+
if (pageEl && !pageEl?.['__isReady']) {
|
|
536
|
+
const el = pageEl.firstElementChild;
|
|
537
|
+
el?.['componentOnReady']?.()?.then(() => {
|
|
538
|
+
runtime.requestAnimationFrame(() => {
|
|
539
|
+
page.onReady?.();
|
|
540
|
+
pageEl['__isReady'] = true;
|
|
541
|
+
});
|
|
542
|
+
});
|
|
543
|
+
onLoad && (pageEl['__page'] = page);
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
load(page, pageConfig = {}, stacksIndex = 0) {
|
|
547
|
+
if (!page)
|
|
548
|
+
return;
|
|
549
|
+
// NOTE: 页面栈推入太晚可能导致 getCurrentPages 无法获取到当前页面实例
|
|
550
|
+
stacks.push(page);
|
|
551
|
+
const param = this.getQuery(stacks.length, '', page.options);
|
|
552
|
+
let pageEl = this.getPageContainer(page);
|
|
553
|
+
if (pageEl) {
|
|
554
|
+
setDisplay(pageEl);
|
|
555
|
+
this.isTabBar && pageEl.classList.add('taro_tabbar_page');
|
|
556
|
+
this.addAnimation(pageEl, stacksIndex === 0);
|
|
557
|
+
page.onShow?.();
|
|
558
|
+
this.bindPageEvents(page, pageEl, pageConfig);
|
|
559
|
+
}
|
|
560
|
+
else {
|
|
561
|
+
page.onLoad?.(param, () => {
|
|
562
|
+
pageEl = this.getPageContainer(page);
|
|
563
|
+
this.isTabBar && pageEl?.classList.add('taro_tabbar_page');
|
|
564
|
+
this.addAnimation(pageEl, stacksIndex === 0);
|
|
565
|
+
this.onReady(page, true);
|
|
566
|
+
page.onShow?.();
|
|
567
|
+
this.bindPageEvents(page, pageEl, pageConfig);
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
unload(page, delta = 1, top = false) {
|
|
572
|
+
if (!page)
|
|
573
|
+
return;
|
|
574
|
+
stacks.delta = --delta;
|
|
575
|
+
stacks.pop();
|
|
576
|
+
if (this.animation && top) {
|
|
577
|
+
if (this.unloadTimer) {
|
|
578
|
+
clearTimeout(this.unloadTimer);
|
|
579
|
+
this.lastUnloadPage?.onUnload?.();
|
|
580
|
+
this.unloadTimer = null;
|
|
581
|
+
}
|
|
582
|
+
this.lastUnloadPage = page;
|
|
583
|
+
const pageEl = this.getPageContainer(page);
|
|
584
|
+
pageEl?.classList.remove('taro_page_stationed');
|
|
585
|
+
pageEl?.classList.remove('taro_page_show');
|
|
586
|
+
this.unloadTimer = setTimeout(() => {
|
|
587
|
+
this.unloadTimer = null;
|
|
588
|
+
this.lastUnloadPage?.onUnload?.();
|
|
589
|
+
}, this.animationDuration);
|
|
590
|
+
}
|
|
591
|
+
else {
|
|
592
|
+
const pageEl = this.getPageContainer(page);
|
|
593
|
+
pageEl?.classList.remove('taro_page_stationed');
|
|
594
|
+
pageEl?.classList.remove('taro_page_show');
|
|
595
|
+
page?.onUnload?.();
|
|
596
|
+
}
|
|
597
|
+
if (delta >= 1)
|
|
598
|
+
this.unload(stacks.last, delta);
|
|
599
|
+
}
|
|
600
|
+
show(page, pageConfig = {}, stacksIndex = 0) {
|
|
601
|
+
if (!page)
|
|
602
|
+
return;
|
|
603
|
+
const param = this.getQuery(stacks.length, '', page.options);
|
|
604
|
+
let pageEl = this.getPageContainer(page);
|
|
605
|
+
if (pageEl) {
|
|
606
|
+
setDisplay(pageEl);
|
|
607
|
+
this.addAnimation(pageEl, stacksIndex === 0);
|
|
608
|
+
page.onShow?.();
|
|
609
|
+
this.bindPageEvents(page, pageEl, pageConfig);
|
|
610
|
+
}
|
|
611
|
+
else {
|
|
612
|
+
page.onLoad?.(param, () => {
|
|
613
|
+
pageEl = this.getPageContainer(page);
|
|
614
|
+
this.addAnimation(pageEl, stacksIndex === 0);
|
|
615
|
+
this.onReady(page, false);
|
|
616
|
+
page.onShow?.();
|
|
617
|
+
this.bindPageEvents(page, pageEl, pageConfig);
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
hide(page) {
|
|
622
|
+
if (!page)
|
|
623
|
+
return;
|
|
624
|
+
// NOTE: 修复多页并发问题,此处可能因为路由跳转过快,执行时页面可能还没有创建成功
|
|
625
|
+
const pageEl = this.getPageContainer(page);
|
|
626
|
+
if (pageEl) {
|
|
627
|
+
if (this.hideTimer) {
|
|
628
|
+
clearTimeout(this.hideTimer);
|
|
629
|
+
this.hideTimer = null;
|
|
630
|
+
setDisplay(this.lastHidePage, 'none');
|
|
631
|
+
}
|
|
632
|
+
this.lastHidePage = pageEl;
|
|
633
|
+
this.hideTimer = setTimeout(() => {
|
|
634
|
+
this.hideTimer = null;
|
|
635
|
+
setDisplay(this.lastHidePage, 'none');
|
|
636
|
+
}, this.animationDuration + this.animationDelay);
|
|
637
|
+
page.onHide?.();
|
|
638
|
+
}
|
|
639
|
+
else {
|
|
640
|
+
setTimeout(() => this.hide(page), 0);
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
addAnimation(pageEl, first = false) {
|
|
644
|
+
if (!pageEl)
|
|
645
|
+
return;
|
|
646
|
+
if (this.animation && !first) {
|
|
647
|
+
setTimeout(() => {
|
|
648
|
+
pageEl.classList.add('taro_page_show');
|
|
649
|
+
setTimeout(() => {
|
|
650
|
+
pageEl.classList.add('taro_page_stationed');
|
|
651
|
+
}, this.animationDuration);
|
|
652
|
+
}, this.animationDelay);
|
|
653
|
+
}
|
|
654
|
+
else {
|
|
655
|
+
pageEl.classList.add('taro_page_show');
|
|
656
|
+
pageEl.classList.add('taro_page_stationed');
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
getPageContainer(page) {
|
|
660
|
+
const path = page ? page?.path : runtime.Current.page?.path;
|
|
661
|
+
const id = path?.replace(/([^a-z0-9\u00a0-\uffff_-])/ig, '\\$1');
|
|
662
|
+
if (page) {
|
|
663
|
+
return document.querySelector(`.taro_page#${id}`);
|
|
664
|
+
}
|
|
665
|
+
const el = (id
|
|
666
|
+
? document.querySelector(`.taro_page#${id}`)
|
|
667
|
+
: document.querySelector('.taro_page') ||
|
|
668
|
+
document.querySelector('.taro_router'));
|
|
669
|
+
return el || window;
|
|
670
|
+
}
|
|
671
|
+
bindPageEvents(page, pageEl, config = {}) {
|
|
672
|
+
if (!pageEl) {
|
|
673
|
+
pageEl = this.getPageContainer();
|
|
674
|
+
}
|
|
675
|
+
const distance = config.onReachBottomDistance || this.config.window?.onReachBottomDistance || 50;
|
|
676
|
+
bindPageScroll(page, pageEl, distance);
|
|
677
|
+
bindPageResize(page);
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
/* eslint-disable dot-notation */
|
|
682
|
+
function createRouter(app, config, framework) {
|
|
683
|
+
RouterConfig.config = config;
|
|
684
|
+
const handler = new PageHandler(config);
|
|
685
|
+
const runtimeHooks = runtime.container.get(runtime.SERVICE_IDENTIFIER.Hooks);
|
|
686
|
+
routesAlias.set(handler.router.customRoutes);
|
|
687
|
+
const basename = handler.router.basename;
|
|
688
|
+
const routes = handler.routes.map(route => ({
|
|
689
|
+
path: routesAlias.getAll(addLeadingSlash(route.path)),
|
|
690
|
+
action: route.load
|
|
691
|
+
}));
|
|
692
|
+
const entryPagePath = config.entryPagePath || routes[0].path?.[0];
|
|
693
|
+
const router = new UniversalRouter__default["default"](routes, { baseUrl: basename || '' });
|
|
694
|
+
const launchParam = handler.getQuery(stacks.length);
|
|
695
|
+
app.onLaunch?.(launchParam);
|
|
696
|
+
const render = async ({ location, action }) => {
|
|
697
|
+
handler.pathname = decodeURI(location.pathname);
|
|
698
|
+
let element;
|
|
699
|
+
try {
|
|
700
|
+
element = await router.resolve(handler.router.forcePath || handler.pathname);
|
|
701
|
+
}
|
|
702
|
+
catch (error) {
|
|
703
|
+
if (error.status === 404) {
|
|
704
|
+
app.onPageNotFound?.({
|
|
705
|
+
path: handler.pathname
|
|
706
|
+
});
|
|
707
|
+
}
|
|
708
|
+
else {
|
|
709
|
+
throw new Error(error);
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
if (!element)
|
|
713
|
+
return;
|
|
714
|
+
const pageConfig = handler.pageConfig;
|
|
715
|
+
let enablePullDownRefresh = config?.window?.enablePullDownRefresh || false;
|
|
716
|
+
runtime.eventCenter.trigger('__taroRouterChange', {
|
|
717
|
+
toLocation: {
|
|
718
|
+
path: handler.pathname
|
|
719
|
+
}
|
|
720
|
+
});
|
|
721
|
+
if (pageConfig) {
|
|
722
|
+
document.title = pageConfig.navigationBarTitleText ?? document.title;
|
|
723
|
+
if (typeof pageConfig.enablePullDownRefresh === 'boolean') {
|
|
724
|
+
enablePullDownRefresh = pageConfig.enablePullDownRefresh;
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
const currentPage = runtime.Current.page;
|
|
728
|
+
const pathname = handler.pathname;
|
|
729
|
+
let shouldLoad = false;
|
|
730
|
+
if (action === 'POP') {
|
|
731
|
+
// NOTE: 浏览器事件退后多次时,该事件只会被触发一次
|
|
732
|
+
const prevIndex = stacks.getPrevIndex(pathname);
|
|
733
|
+
const delta = stacks.getDelta(pathname);
|
|
734
|
+
handler.unload(currentPage, delta, prevIndex > -1);
|
|
735
|
+
if (prevIndex > -1) {
|
|
736
|
+
handler.show(stacks.getItem(prevIndex), pageConfig, prevIndex);
|
|
737
|
+
}
|
|
738
|
+
else {
|
|
739
|
+
shouldLoad = true;
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
else {
|
|
743
|
+
if (handler.isTabBar) {
|
|
744
|
+
if (handler.isSamePage(currentPage))
|
|
745
|
+
return;
|
|
746
|
+
const prevIndex = stacks.getPrevIndex(pathname, 0);
|
|
747
|
+
handler.hide(currentPage);
|
|
748
|
+
if (prevIndex > -1) {
|
|
749
|
+
// NOTE: tabbar 页且之前出现过,直接复用
|
|
750
|
+
return handler.show(stacks.getItem(prevIndex), pageConfig, prevIndex);
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
else if (action === 'REPLACE') {
|
|
754
|
+
const delta = stacks.getDelta(pathname);
|
|
755
|
+
// NOTE: 页面路由记录并不会清空,只是移除掉缓存的 stack 以及页面
|
|
756
|
+
handler.unload(currentPage, delta);
|
|
757
|
+
}
|
|
758
|
+
else if (action === 'PUSH') {
|
|
759
|
+
handler.hide(currentPage);
|
|
760
|
+
}
|
|
761
|
+
shouldLoad = true;
|
|
762
|
+
}
|
|
763
|
+
if (shouldLoad || stacks.length < 1) {
|
|
764
|
+
const el = element.default ?? element;
|
|
765
|
+
const loadConfig = { ...pageConfig };
|
|
766
|
+
const stacksIndex = stacks.length;
|
|
767
|
+
delete loadConfig['path'];
|
|
768
|
+
delete loadConfig['load'];
|
|
769
|
+
const page = runtime.createPageConfig(enablePullDownRefresh ? runtimeHooks.createPullDownComponent?.(el, location.pathname, framework, handler.PullDownRefresh) : el, pathname + runtime.stringify(handler.getQuery(stacksIndex)), {}, loadConfig);
|
|
770
|
+
return handler.load(page, pageConfig, stacksIndex);
|
|
771
|
+
}
|
|
772
|
+
};
|
|
773
|
+
if (exports.history.location.pathname === '/') {
|
|
774
|
+
const stripped = stripBasename(exports.history.location.pathname, handler.basename);
|
|
775
|
+
if (stripped === '/' || stripped === '') {
|
|
776
|
+
exports.history.replace(prependBasename(entryPagePath + exports.history.location.search));
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
render({ location: exports.history.location, action: history.Action.Push });
|
|
780
|
+
app.onShow?.(launchParam);
|
|
781
|
+
return exports.history.listen(render);
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
class MultiPageHandler {
|
|
785
|
+
config;
|
|
786
|
+
constructor(config) {
|
|
787
|
+
this.config = config;
|
|
788
|
+
this.mount();
|
|
789
|
+
}
|
|
790
|
+
get appId() { return 'app'; }
|
|
791
|
+
get router() { return this.config.router; }
|
|
792
|
+
get routerMode() { return this.router.mode || 'hash'; }
|
|
793
|
+
get customRoutes() { return this.router.customRoutes || {}; }
|
|
794
|
+
get tabBarList() { return this.config.tabBar?.list || []; }
|
|
795
|
+
get PullDownRefresh() { return this.config.PullDownRefresh; }
|
|
796
|
+
set pathname(p) { this.router.pathname = p; }
|
|
797
|
+
get pathname() { return this.router.pathname; }
|
|
798
|
+
get basename() { return this.router.basename || ''; }
|
|
799
|
+
get pageConfig() { return this.config.route; }
|
|
800
|
+
get isTabBar() {
|
|
801
|
+
const routePath = stripBasename(this.pathname, this.basename);
|
|
802
|
+
const pagePath = Object.entries(this.customRoutes).find(([, target]) => {
|
|
803
|
+
if (typeof target === 'string') {
|
|
804
|
+
return target === routePath;
|
|
805
|
+
}
|
|
806
|
+
else if (target?.length > 0) {
|
|
807
|
+
return target.includes(routePath);
|
|
808
|
+
}
|
|
809
|
+
return false;
|
|
810
|
+
})?.[0] || routePath;
|
|
811
|
+
return !!pagePath && this.tabBarList.some(t => t.pagePath === pagePath);
|
|
812
|
+
}
|
|
813
|
+
get search() { return location.search.substr(1); }
|
|
814
|
+
getQuery(search = '', options = {}) {
|
|
815
|
+
search = search ? `${search}&${this.search}` : this.search;
|
|
816
|
+
const query = search
|
|
817
|
+
? queryString__default["default"].parse(search)
|
|
818
|
+
: {};
|
|
819
|
+
return { ...query, ...options };
|
|
820
|
+
}
|
|
821
|
+
mount() {
|
|
822
|
+
setHistoryMode(this.routerMode, this.router.basename);
|
|
823
|
+
document.getElementById('app')?.remove();
|
|
824
|
+
const app = document.createElement('div');
|
|
825
|
+
app.id = this.appId;
|
|
826
|
+
app.classList.add('taro_router');
|
|
827
|
+
if (this.tabBarList.length > 1) {
|
|
828
|
+
const container = document.createElement('div');
|
|
829
|
+
container.classList.add('taro-tabbar__container');
|
|
830
|
+
container.id = 'container';
|
|
831
|
+
const panel = document.createElement('div');
|
|
832
|
+
panel.classList.add('taro-tabbar__panel');
|
|
833
|
+
panel.appendChild(app);
|
|
834
|
+
container.appendChild(panel);
|
|
835
|
+
document.body.appendChild(container);
|
|
836
|
+
initTabbar(this.config);
|
|
837
|
+
}
|
|
838
|
+
else {
|
|
839
|
+
document.body.appendChild(app);
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
onReady(page, onLoad = true) {
|
|
843
|
+
const pageEl = this.getPageContainer(page);
|
|
844
|
+
if (pageEl && !pageEl?.['__isReady']) {
|
|
845
|
+
const el = pageEl.firstElementChild;
|
|
846
|
+
el?.['componentOnReady']?.();
|
|
847
|
+
onLoad && (pageEl['__page'] = page);
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
load(page, pageConfig = {}) {
|
|
851
|
+
if (!page)
|
|
852
|
+
return;
|
|
853
|
+
page.onLoad?.(this.getQuery('', page.options), () => {
|
|
854
|
+
const pageEl = this.getPageContainer(page);
|
|
855
|
+
this.isTabBar && pageEl?.classList.add('taro_tabbar_page');
|
|
856
|
+
this.onReady(page, true);
|
|
857
|
+
page.onShow?.();
|
|
858
|
+
this.bindPageEvents(page, pageEl, pageConfig);
|
|
859
|
+
});
|
|
860
|
+
}
|
|
861
|
+
getPageContainer(page) {
|
|
862
|
+
const path = page ? page?.path : runtime.Current.page?.path;
|
|
863
|
+
const id = path?.replace(/([^a-z0-9\u00a0-\uffff_-])/ig, '\\$1');
|
|
864
|
+
if (page) {
|
|
865
|
+
return document.querySelector(`.taro_page#${id}`);
|
|
866
|
+
}
|
|
867
|
+
const el = (id
|
|
868
|
+
? document.querySelector(`.taro_page#${id}`)
|
|
869
|
+
: document.querySelector('.taro_page') ||
|
|
870
|
+
document.querySelector('.taro_router'));
|
|
871
|
+
return el || window;
|
|
872
|
+
}
|
|
873
|
+
bindPageEvents(page, pageEl, config = {}) {
|
|
874
|
+
if (!pageEl) {
|
|
875
|
+
pageEl = this.getPageContainer();
|
|
876
|
+
}
|
|
877
|
+
const distance = config.onReachBottomDistance || this.config.window?.onReachBottomDistance || 50;
|
|
878
|
+
bindPageScroll(page, pageEl, distance);
|
|
879
|
+
bindPageResize(page);
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
/* eslint-disable dot-notation */
|
|
884
|
+
// TODO 支持多路由 (APP 生命周期仅触发一次)
|
|
885
|
+
/** Note: 关于多页面应用
|
|
886
|
+
* - 需要配置路由映射(根目录跳转、404 页面……)
|
|
887
|
+
* - app.onPageNotFound 事件不支持
|
|
888
|
+
* - 应用生命周期可能多次触发
|
|
889
|
+
* - TabBar 会多次加载
|
|
890
|
+
* - 不支持路由动画
|
|
891
|
+
*/
|
|
892
|
+
async function createMultiRouter(app, config, framework) {
|
|
893
|
+
RouterConfig.config = config;
|
|
894
|
+
const handler = new MultiPageHandler(config);
|
|
895
|
+
const runtimeHooks = runtime.container.get(runtime.SERVICE_IDENTIFIER.Hooks);
|
|
896
|
+
const launchParam = handler.getQuery();
|
|
897
|
+
app.onLaunch?.(launchParam);
|
|
898
|
+
const pathName = config.pageName;
|
|
899
|
+
const pageConfig = handler.pageConfig;
|
|
900
|
+
let element;
|
|
901
|
+
try {
|
|
902
|
+
element = await pageConfig.load?.();
|
|
903
|
+
}
|
|
904
|
+
catch (error) {
|
|
905
|
+
throw new Error(error);
|
|
906
|
+
}
|
|
907
|
+
if (!element)
|
|
908
|
+
return;
|
|
909
|
+
let enablePullDownRefresh = config?.window?.enablePullDownRefresh || false;
|
|
910
|
+
runtime.eventCenter.trigger('__taroRouterChange', {
|
|
911
|
+
toLocation: {
|
|
912
|
+
path: pathName
|
|
913
|
+
}
|
|
914
|
+
});
|
|
915
|
+
if (pageConfig) {
|
|
916
|
+
document.title = pageConfig.navigationBarTitleText ?? document.title;
|
|
917
|
+
if (typeof pageConfig.enablePullDownRefresh === 'boolean') {
|
|
918
|
+
enablePullDownRefresh = pageConfig.enablePullDownRefresh;
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
const el = element.default ?? element;
|
|
922
|
+
const loadConfig = { ...pageConfig };
|
|
923
|
+
delete loadConfig['path'];
|
|
924
|
+
delete loadConfig['load'];
|
|
925
|
+
const page = runtime.createPageConfig(enablePullDownRefresh ? runtimeHooks.createPullDownComponent?.(el, location.pathname, framework, config.PullDownRefresh) : el, pathName + runtime.stringify(launchParam), {}, loadConfig);
|
|
926
|
+
handler.load(page, pageConfig);
|
|
927
|
+
app.onShow?.(launchParam);
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
exports.createMultiRouter = createMultiRouter;
|
|
931
|
+
exports.createRouter = createRouter;
|
|
932
|
+
exports.getCurrentPages = getCurrentPages;
|
|
933
|
+
exports.navigateBack = navigateBack;
|
|
934
|
+
exports.navigateTo = navigateTo;
|
|
935
|
+
exports.reLaunch = reLaunch;
|
|
936
|
+
exports.redirectTo = redirectTo;
|
|
937
|
+
exports.switchTab = switchTab;
|
|
938
|
+
//# sourceMappingURL=index.js.map
|