@tarojs/router 3.7.0-alpha.2 → 3.7.0-alpha.22
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/api.js +6 -1
- package/dist/events/scroll.d.ts +1 -1
- package/dist/events/scroll.js +3 -3
- package/dist/history.js +1 -1
- package/dist/index.cjs.d.ts +0 -1
- package/dist/index.cjs.js +277 -142
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.d.ts +0 -1
- package/dist/index.esm.js +279 -144
- package/dist/index.esm.js.map +1 -1
- package/dist/router/index.js +2 -2
- package/dist/router/mpa.d.ts +1 -1
- package/dist/router/mpa.js +4 -1
- package/dist/router/multi-page.d.ts +4 -1
- package/dist/router/multi-page.js +56 -11
- package/dist/router/page.d.ts +4 -1
- package/dist/router/page.js +57 -22
- package/dist/router/spa.d.ts +1 -1
- package/dist/router/spa.js +23 -17
- package/dist/style.d.ts +8 -0
- package/dist/style.js +71 -0
- package/package.json +10 -9
- package/dist/animation.d.ts +0 -4
- package/dist/animation.js +0 -29
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/* eslint-disable dot-notation */
|
|
2
|
-
import { Current } from '@tarojs/runtime';
|
|
2
|
+
import { Current, eventCenter } from '@tarojs/runtime';
|
|
3
3
|
import queryString from 'query-string';
|
|
4
4
|
import { bindPageResize } from '../events/resize';
|
|
5
5
|
import { bindPageScroll } from '../events/scroll';
|
|
6
6
|
import { setHistoryMode } from '../history';
|
|
7
|
+
import { loadRouterStyle } from '../style';
|
|
7
8
|
import { initTabbar } from '../tabbar';
|
|
8
9
|
import { addLeadingSlash, stripBasename } from '../utils';
|
|
9
10
|
export default class MultiPageHandler {
|
|
@@ -36,6 +37,17 @@ export default class MultiPageHandler {
|
|
|
36
37
|
return !!pagePath && this.tabBarList.some(t => t.pagePath === pagePath);
|
|
37
38
|
}
|
|
38
39
|
get search() { return location.search.substr(1); }
|
|
40
|
+
get usingWindowScroll() {
|
|
41
|
+
var _a;
|
|
42
|
+
let usingWindowScroll = true;
|
|
43
|
+
if (typeof ((_a = this.pageConfig) === null || _a === void 0 ? void 0 : _a.usingWindowScroll) === 'boolean') {
|
|
44
|
+
usingWindowScroll = this.pageConfig.usingWindowScroll;
|
|
45
|
+
}
|
|
46
|
+
const win = window;
|
|
47
|
+
win.__taroAppConfig || (win.__taroAppConfig = {});
|
|
48
|
+
win.__taroAppConfig.usingWindowScroll = usingWindowScroll;
|
|
49
|
+
return usingWindowScroll;
|
|
50
|
+
}
|
|
39
51
|
getQuery(search = '', options = {}) {
|
|
40
52
|
search = search ? `${search}&${this.search}` : this.search;
|
|
41
53
|
const query = search
|
|
@@ -45,6 +57,7 @@ export default class MultiPageHandler {
|
|
|
45
57
|
}
|
|
46
58
|
mount() {
|
|
47
59
|
setHistoryMode(this.routerMode, this.router.basename);
|
|
60
|
+
loadRouterStyle(this.usingWindowScroll);
|
|
48
61
|
const appId = this.appId;
|
|
49
62
|
let app = document.getElementById(appId);
|
|
50
63
|
let isPosition = true;
|
|
@@ -81,7 +94,20 @@ export default class MultiPageHandler {
|
|
|
81
94
|
const pageEl = this.getPageContainer(page);
|
|
82
95
|
if (pageEl && !(pageEl === null || pageEl === void 0 ? void 0 : pageEl['__isReady'])) {
|
|
83
96
|
const el = pageEl.firstElementChild;
|
|
84
|
-
|
|
97
|
+
const componentOnReady = el === null || el === void 0 ? void 0 : el['componentOnReady'];
|
|
98
|
+
if (componentOnReady) {
|
|
99
|
+
componentOnReady === null || componentOnReady === void 0 ? void 0 : componentOnReady().then(() => {
|
|
100
|
+
requestAnimationFrame(() => {
|
|
101
|
+
var _a;
|
|
102
|
+
(_a = page.onReady) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
103
|
+
pageEl['__isReady'] = true;
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
(_a = page.onReady) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
109
|
+
pageEl['__isReady'] = true;
|
|
110
|
+
}
|
|
85
111
|
onLoad && (pageEl['__page'] = page);
|
|
86
112
|
}
|
|
87
113
|
}
|
|
@@ -91,11 +117,14 @@ export default class MultiPageHandler {
|
|
|
91
117
|
return;
|
|
92
118
|
(_a = page.onLoad) === null || _a === void 0 ? void 0 : _a.call(page, this.getQuery('', page.options), () => {
|
|
93
119
|
var _a;
|
|
94
|
-
|
|
95
|
-
|
|
120
|
+
if (this.isTabBar) {
|
|
121
|
+
const pageEl = this.getPageContainer(page);
|
|
122
|
+
pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.add('taro_tabbar_page');
|
|
123
|
+
}
|
|
96
124
|
this.onReady(page, true);
|
|
97
125
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
98
|
-
this.bindPageEvents(page,
|
|
126
|
+
this.bindPageEvents(page, pageConfig);
|
|
127
|
+
this.triggerRouterChange();
|
|
99
128
|
});
|
|
100
129
|
}
|
|
101
130
|
getPageContainer(page) {
|
|
@@ -109,15 +138,31 @@ export default class MultiPageHandler {
|
|
|
109
138
|
? document.querySelector(`.taro_page#${id}`)
|
|
110
139
|
: document.querySelector('.taro_page') ||
|
|
111
140
|
document.querySelector('.taro_router'));
|
|
112
|
-
return el
|
|
141
|
+
return el;
|
|
142
|
+
}
|
|
143
|
+
getScrollingElement(page) {
|
|
144
|
+
if (this.usingWindowScroll)
|
|
145
|
+
return window;
|
|
146
|
+
return this.getPageContainer(page) || window;
|
|
113
147
|
}
|
|
114
|
-
bindPageEvents(page,
|
|
148
|
+
bindPageEvents(page, config = {}) {
|
|
115
149
|
var _a;
|
|
116
|
-
|
|
117
|
-
pageEl = this.getPageContainer();
|
|
118
|
-
}
|
|
150
|
+
const scrollEl = this.getScrollingElement(page);
|
|
119
151
|
const distance = config.onReachBottomDistance || ((_a = this.config.window) === null || _a === void 0 ? void 0 : _a.onReachBottomDistance) || 50;
|
|
120
|
-
bindPageScroll(page,
|
|
152
|
+
bindPageScroll(page, scrollEl, distance);
|
|
121
153
|
bindPageResize(page);
|
|
122
154
|
}
|
|
155
|
+
triggerRouterChange() {
|
|
156
|
+
/**
|
|
157
|
+
* @tarojs/runtime 中生命周期跑在 promise 中,所以这里需要 setTimeout 延迟事件调用
|
|
158
|
+
* TODO 考虑将生命周期返回 Promise,用于处理相关事件调用顺序
|
|
159
|
+
*/
|
|
160
|
+
setTimeout(() => {
|
|
161
|
+
eventCenter.trigger('__afterTaroRouterChange', {
|
|
162
|
+
toLocation: {
|
|
163
|
+
path: this.pathname
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}, 0);
|
|
167
|
+
}
|
|
123
168
|
}
|
package/dist/router/page.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ export default class PageHandler {
|
|
|
28
28
|
isTabBar(pathname: string): boolean;
|
|
29
29
|
isSamePage(page?: PageInstance | null): boolean;
|
|
30
30
|
get search(): string;
|
|
31
|
+
get usingWindowScroll(): boolean;
|
|
31
32
|
getQuery(stamp?: string, search?: string, options?: Record<string, unknown>): {
|
|
32
33
|
[x: string]: unknown;
|
|
33
34
|
};
|
|
@@ -39,5 +40,7 @@ export default class PageHandler {
|
|
|
39
40
|
hide(page?: PageInstance | null): void;
|
|
40
41
|
addAnimation(pageEl?: HTMLElement | null, first?: boolean): void;
|
|
41
42
|
getPageContainer(page?: PageInstance | null): HTMLElement | null;
|
|
42
|
-
|
|
43
|
+
getScrollingElement(page?: PageInstance | null): (Window & typeof globalThis) | HTMLElement;
|
|
44
|
+
bindPageEvents(page: PageInstance, config?: Partial<PageConfig>): void;
|
|
45
|
+
triggerRouterChange(): void;
|
|
43
46
|
}
|
package/dist/router/page.js
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
/* eslint-disable dot-notation */
|
|
2
|
-
import { Current, requestAnimationFrame } from '@tarojs/runtime';
|
|
2
|
+
import { Current, eventCenter, requestAnimationFrame } from '@tarojs/runtime';
|
|
3
3
|
import queryString from 'query-string';
|
|
4
|
-
import { loadAnimateStyle } from '../animation';
|
|
5
4
|
import { bindPageResize } from '../events/resize';
|
|
6
5
|
import { bindPageScroll } from '../events/scroll';
|
|
7
|
-
import { setHistoryMode } from '../history';
|
|
6
|
+
import { history, setHistoryMode } from '../history';
|
|
7
|
+
import { loadAnimateStyle, loadRouterStyle } from '../style';
|
|
8
8
|
import { initTabbar } from '../tabbar';
|
|
9
9
|
import { addLeadingSlash, getCurrentPage, getHomePage, routesAlias, stripBasename, stripTrailing } from '../utils';
|
|
10
10
|
import stacks from './stack';
|
|
11
|
-
function setDisplay(el, type = '') {
|
|
12
|
-
if (el) {
|
|
13
|
-
el.style.display = type;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
11
|
export default class PageHandler {
|
|
17
12
|
constructor(config) {
|
|
18
13
|
this.defaultAnimation = { duration: 300, delay: 50 };
|
|
@@ -92,6 +87,17 @@ export default class PageHandler {
|
|
|
92
87
|
}
|
|
93
88
|
return search.substring(1);
|
|
94
89
|
}
|
|
90
|
+
get usingWindowScroll() {
|
|
91
|
+
var _a;
|
|
92
|
+
let usingWindowScroll = false;
|
|
93
|
+
if (typeof ((_a = this.pageConfig) === null || _a === void 0 ? void 0 : _a.usingWindowScroll) === 'boolean') {
|
|
94
|
+
usingWindowScroll = this.pageConfig.usingWindowScroll;
|
|
95
|
+
}
|
|
96
|
+
const win = window;
|
|
97
|
+
win.__taroAppConfig || (win.__taroAppConfig = {});
|
|
98
|
+
win.__taroAppConfig.usingWindowScroll = usingWindowScroll;
|
|
99
|
+
return usingWindowScroll;
|
|
100
|
+
}
|
|
95
101
|
getQuery(stamp = '', search = '', options = {}) {
|
|
96
102
|
search = search ? `${search}&${this.search}` : this.search;
|
|
97
103
|
const query = search
|
|
@@ -102,7 +108,9 @@ export default class PageHandler {
|
|
|
102
108
|
}
|
|
103
109
|
mount() {
|
|
104
110
|
setHistoryMode(this.routerMode, this.router.basename);
|
|
111
|
+
this.pathname = history.location.pathname;
|
|
105
112
|
this.animation && loadAnimateStyle(this.animationDuration);
|
|
113
|
+
loadRouterStyle(this.usingWindowScroll);
|
|
106
114
|
const appId = this.appId;
|
|
107
115
|
let app = document.getElementById(appId);
|
|
108
116
|
let isPosition = true;
|
|
@@ -165,11 +173,12 @@ export default class PageHandler {
|
|
|
165
173
|
const param = this.getQuery(stampId, '', page.options);
|
|
166
174
|
let pageEl = this.getPageContainer(page);
|
|
167
175
|
if (pageEl) {
|
|
168
|
-
|
|
176
|
+
pageEl.classList.remove('taro_page_shade');
|
|
169
177
|
this.isTabBar(this.pathname) && pageEl.classList.add('taro_tabbar_page');
|
|
170
178
|
this.addAnimation(pageEl, pageNo === 0);
|
|
171
179
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
172
|
-
this.bindPageEvents(page,
|
|
180
|
+
this.bindPageEvents(page, pageConfig);
|
|
181
|
+
this.triggerRouterChange();
|
|
173
182
|
}
|
|
174
183
|
else {
|
|
175
184
|
(_b = page.onLoad) === null || _b === void 0 ? void 0 : _b.call(page, param, () => {
|
|
@@ -179,7 +188,8 @@ export default class PageHandler {
|
|
|
179
188
|
this.addAnimation(pageEl, pageNo === 0);
|
|
180
189
|
this.onReady(page, true);
|
|
181
190
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
182
|
-
this.bindPageEvents(page,
|
|
191
|
+
this.bindPageEvents(page, pageConfig);
|
|
192
|
+
this.triggerRouterChange();
|
|
183
193
|
});
|
|
184
194
|
}
|
|
185
195
|
}
|
|
@@ -199,10 +209,14 @@ export default class PageHandler {
|
|
|
199
209
|
const pageEl = this.getPageContainer(page);
|
|
200
210
|
pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.remove('taro_page_stationed');
|
|
201
211
|
pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.remove('taro_page_show');
|
|
212
|
+
if (pageEl) {
|
|
213
|
+
pageEl.style.zIndex = '1';
|
|
214
|
+
}
|
|
202
215
|
this.unloadTimer = setTimeout(() => {
|
|
203
216
|
var _a, _b;
|
|
204
217
|
this.unloadTimer = null;
|
|
205
218
|
(_b = (_a = this.lastUnloadPage) === null || _a === void 0 ? void 0 : _a.onUnload) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
219
|
+
eventCenter.trigger('__taroPageOnShowAfterDestroyed');
|
|
206
220
|
}, this.animationDuration);
|
|
207
221
|
}
|
|
208
222
|
else {
|
|
@@ -210,6 +224,9 @@ export default class PageHandler {
|
|
|
210
224
|
pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.remove('taro_page_stationed');
|
|
211
225
|
pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.remove('taro_page_show');
|
|
212
226
|
(_c = page === null || page === void 0 ? void 0 : page.onUnload) === null || _c === void 0 ? void 0 : _c.call(page);
|
|
227
|
+
setTimeout(() => {
|
|
228
|
+
eventCenter.trigger('__taroPageOnShowAfterDestroyed');
|
|
229
|
+
}, 0);
|
|
213
230
|
}
|
|
214
231
|
if (delta >= 1)
|
|
215
232
|
this.unload(stacks.last, delta);
|
|
@@ -221,10 +238,11 @@ export default class PageHandler {
|
|
|
221
238
|
const param = this.getQuery(page['$taroParams']['stamp'], '', page.options);
|
|
222
239
|
let pageEl = this.getPageContainer(page);
|
|
223
240
|
if (pageEl) {
|
|
224
|
-
|
|
241
|
+
pageEl.classList.remove('taro_page_shade');
|
|
225
242
|
this.addAnimation(pageEl, pageNo === 0);
|
|
226
243
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
227
|
-
this.bindPageEvents(page,
|
|
244
|
+
this.bindPageEvents(page, pageConfig);
|
|
245
|
+
this.triggerRouterChange();
|
|
228
246
|
}
|
|
229
247
|
else {
|
|
230
248
|
(_b = page.onLoad) === null || _b === void 0 ? void 0 : _b.call(page, param, () => {
|
|
@@ -233,7 +251,8 @@ export default class PageHandler {
|
|
|
233
251
|
this.addAnimation(pageEl, pageNo === 0);
|
|
234
252
|
this.onReady(page, false);
|
|
235
253
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
236
|
-
this.bindPageEvents(page,
|
|
254
|
+
this.bindPageEvents(page, pageConfig);
|
|
255
|
+
this.triggerRouterChange();
|
|
237
256
|
});
|
|
238
257
|
}
|
|
239
258
|
}
|
|
@@ -247,12 +266,12 @@ export default class PageHandler {
|
|
|
247
266
|
if (this.hideTimer) {
|
|
248
267
|
clearTimeout(this.hideTimer);
|
|
249
268
|
this.hideTimer = null;
|
|
250
|
-
|
|
269
|
+
pageEl.classList.add('taro_page_shade');
|
|
251
270
|
}
|
|
252
271
|
this.lastHidePage = pageEl;
|
|
253
272
|
this.hideTimer = setTimeout(() => {
|
|
254
273
|
this.hideTimer = null;
|
|
255
|
-
|
|
274
|
+
pageEl.classList.add('taro_page_shade');
|
|
256
275
|
}, this.animationDuration + this.animationDelay);
|
|
257
276
|
(_a = page.onHide) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
258
277
|
}
|
|
@@ -287,15 +306,31 @@ export default class PageHandler {
|
|
|
287
306
|
? document.querySelector(`.taro_page#${id}`)
|
|
288
307
|
: document.querySelector('.taro_page') ||
|
|
289
308
|
document.querySelector('.taro_router'));
|
|
290
|
-
return el
|
|
309
|
+
return el;
|
|
310
|
+
}
|
|
311
|
+
getScrollingElement(page) {
|
|
312
|
+
if (this.usingWindowScroll)
|
|
313
|
+
return window;
|
|
314
|
+
return this.getPageContainer(page) || window;
|
|
291
315
|
}
|
|
292
|
-
bindPageEvents(page,
|
|
316
|
+
bindPageEvents(page, config = {}) {
|
|
293
317
|
var _a;
|
|
294
|
-
|
|
295
|
-
pageEl = this.getPageContainer();
|
|
296
|
-
}
|
|
318
|
+
const scrollEl = this.getScrollingElement(page);
|
|
297
319
|
const distance = config.onReachBottomDistance || ((_a = this.config.window) === null || _a === void 0 ? void 0 : _a.onReachBottomDistance) || 50;
|
|
298
|
-
bindPageScroll(page,
|
|
320
|
+
bindPageScroll(page, scrollEl, distance);
|
|
299
321
|
bindPageResize(page);
|
|
300
322
|
}
|
|
323
|
+
triggerRouterChange() {
|
|
324
|
+
/**
|
|
325
|
+
* @tarojs/runtime 中生命周期跑在 promise 中,所以这里需要 setTimeout 延迟事件调用
|
|
326
|
+
* TODO 考虑将生命周期返回 Promise,用于处理相关事件调用顺序
|
|
327
|
+
*/
|
|
328
|
+
setTimeout(() => {
|
|
329
|
+
eventCenter.trigger('__afterTaroRouterChange', {
|
|
330
|
+
toLocation: {
|
|
331
|
+
path: this.pathname
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
}, 0);
|
|
335
|
+
}
|
|
301
336
|
}
|
package/dist/router/spa.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { AppInstance } from '@tarojs/runtime';
|
|
1
|
+
import type { AppInstance } from '@tarojs/runtime';
|
|
2
2
|
import type { SpaRouterConfig } from '../../types/router';
|
|
3
3
|
export declare function createRouter(app: AppInstance, config: SpaRouterConfig, framework?: string): () => void;
|
package/dist/router/spa.js
CHANGED
|
@@ -21,6 +21,9 @@ const createStampId = incrementId();
|
|
|
21
21
|
let launchStampId = createStampId();
|
|
22
22
|
export function createRouter(app, config, framework) {
|
|
23
23
|
var _a, _b;
|
|
24
|
+
if (typeof app.onUnhandledRejection === 'function') {
|
|
25
|
+
window.addEventListener('unhandledrejection', app.onUnhandledRejection);
|
|
26
|
+
}
|
|
24
27
|
RouterConfig.config = config;
|
|
25
28
|
const handler = new PageHandler(config);
|
|
26
29
|
routesAlias.set(handler.router.customRoutes);
|
|
@@ -45,8 +48,10 @@ export function createRouter(app, config, framework) {
|
|
|
45
48
|
(_a = app.onLaunch) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
|
|
46
49
|
app.onError && window.addEventListener('error', e => { var _a; return (_a = app.onError) === null || _a === void 0 ? void 0 : _a.call(app, e.message); });
|
|
47
50
|
const render = ({ location, action }) => __awaiter(this, void 0, void 0, function* () {
|
|
48
|
-
var _c, _d, _e, _f, _g;
|
|
51
|
+
var _c, _d, _e, _f, _g, _h;
|
|
49
52
|
handler.pathname = decodeURI(location.pathname);
|
|
53
|
+
if ((_c = window.__taroAppConfig) === null || _c === void 0 ? void 0 : _c.usingWindowScroll)
|
|
54
|
+
window.scrollTo(0, 0);
|
|
50
55
|
eventCenter.trigger('__taroRouterChange', {
|
|
51
56
|
toLocation: {
|
|
52
57
|
path: handler.pathname
|
|
@@ -59,9 +64,13 @@ export function createRouter(app, config, framework) {
|
|
|
59
64
|
}
|
|
60
65
|
catch (error) {
|
|
61
66
|
if (error.status === 404) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
67
|
+
const notFoundEvent = {
|
|
68
|
+
isEntryPage: stacks.length === 0,
|
|
69
|
+
path: handler.pathname,
|
|
70
|
+
query: handler.getQuery(createStampId()),
|
|
71
|
+
};
|
|
72
|
+
(_d = app.onPageNotFound) === null || _d === void 0 ? void 0 : _d.call(app, notFoundEvent);
|
|
73
|
+
eventCenter.trigger('__taroRouterNotFound', notFoundEvent);
|
|
65
74
|
}
|
|
66
75
|
else if (/Loading hot update .* failed./.test(error.message)) {
|
|
67
76
|
// NOTE: webpack5 与 prebundle 搭配使用时,开发环境下初次启动时偶发错误,由于 HMR 加载 chunk hash 错误,导致热更新失败
|
|
@@ -74,16 +83,16 @@ export function createRouter(app, config, framework) {
|
|
|
74
83
|
if (!element)
|
|
75
84
|
return;
|
|
76
85
|
const pageConfig = handler.pageConfig;
|
|
77
|
-
let enablePullDownRefresh = ((
|
|
86
|
+
let enablePullDownRefresh = ((_e = config === null || config === void 0 ? void 0 : config.window) === null || _e === void 0 ? void 0 : _e.enablePullDownRefresh) || false;
|
|
78
87
|
if (pageConfig) {
|
|
79
|
-
setTitle((
|
|
88
|
+
setTitle((_f = pageConfig.navigationBarTitleText) !== null && _f !== void 0 ? _f : document.title);
|
|
80
89
|
if (typeof pageConfig.enablePullDownRefresh === 'boolean') {
|
|
81
90
|
enablePullDownRefresh = pageConfig.enablePullDownRefresh;
|
|
82
91
|
}
|
|
83
92
|
}
|
|
84
93
|
const currentPage = Current.page;
|
|
85
94
|
const pathname = handler.pathname;
|
|
86
|
-
const methodName = (
|
|
95
|
+
const methodName = (_g = stacks.method) !== null && _g !== void 0 ? _g : '';
|
|
87
96
|
const cacheTabs = stacks.getTabs();
|
|
88
97
|
let shouldLoad = false;
|
|
89
98
|
stacks.method = '';
|
|
@@ -108,11 +117,11 @@ export function createRouter(app, config, framework) {
|
|
|
108
117
|
else if (stacks.length > 0) {
|
|
109
118
|
const firstIns = stacks.getItem(0);
|
|
110
119
|
if (handler.isTabBar(firstIns.path)) {
|
|
111
|
-
handler.unload(currentPage, stacks.length - 1);
|
|
120
|
+
handler.unload(currentPage, stacks.length - 1, true);
|
|
112
121
|
stacks.pushTab(firstIns.path.split('?')[0]);
|
|
113
122
|
}
|
|
114
123
|
else {
|
|
115
|
-
handler.unload(currentPage, stacks.length);
|
|
124
|
+
handler.unload(currentPage, stacks.length, true);
|
|
116
125
|
}
|
|
117
126
|
}
|
|
118
127
|
if (cacheTabs[handler.pathname]) {
|
|
@@ -129,7 +138,9 @@ export function createRouter(app, config, framework) {
|
|
|
129
138
|
if (currentPage !== stacks.getItem(prevIndex)) {
|
|
130
139
|
handler.unload(currentPage, delta, prevIndex > -1);
|
|
131
140
|
if (prevIndex > -1) {
|
|
132
|
-
|
|
141
|
+
eventCenter.once('__taroPageOnShowAfterDestroyed', () => {
|
|
142
|
+
handler.show(stacks.getItem(prevIndex), pageConfig, prevIndex);
|
|
143
|
+
});
|
|
133
144
|
}
|
|
134
145
|
else {
|
|
135
146
|
shouldLoad = true;
|
|
@@ -147,7 +158,7 @@ export function createRouter(app, config, framework) {
|
|
|
147
158
|
shouldLoad = true;
|
|
148
159
|
}
|
|
149
160
|
if (shouldLoad || stacks.length < 1) {
|
|
150
|
-
const el = (
|
|
161
|
+
const el = (_h = element.default) !== null && _h !== void 0 ? _h : element;
|
|
151
162
|
const loadConfig = Object.assign({}, pageConfig);
|
|
152
163
|
const stacksIndex = stacks.length;
|
|
153
164
|
delete loadConfig['path'];
|
|
@@ -160,16 +171,11 @@ export function createRouter(app, config, framework) {
|
|
|
160
171
|
else {
|
|
161
172
|
pageStampId = createStampId();
|
|
162
173
|
}
|
|
163
|
-
const page = createPageConfig(enablePullDownRefresh ? hooks.call('createPullDownComponent', el,
|
|
174
|
+
const page = createPageConfig(enablePullDownRefresh ? hooks.call('createPullDownComponent', el, pathname, framework, handler.PullDownRefresh, pageStampId) : el, pathname + stringify(handler.getQuery(pageStampId)), {}, loadConfig);
|
|
164
175
|
if (params)
|
|
165
176
|
page.options = params;
|
|
166
177
|
handler.load(page, pageConfig, pageStampId, stacksIndex);
|
|
167
178
|
}
|
|
168
|
-
eventCenter.trigger('__afterTaroRouterChange', {
|
|
169
|
-
toLocation: {
|
|
170
|
-
path: handler.pathname
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
179
|
});
|
|
174
180
|
const routePath = addLeadingSlash(stripBasename(history.location.pathname, handler.basename));
|
|
175
181
|
if (routePath === '/') {
|
package/dist/style.d.ts
ADDED
package/dist/style.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 插入页面动画需要的样式
|
|
3
|
+
*/
|
|
4
|
+
export function loadAnimateStyle(ms = 300) {
|
|
5
|
+
const css = `
|
|
6
|
+
.taro_router > .taro_page {
|
|
7
|
+
position: absolute;
|
|
8
|
+
left: 0;
|
|
9
|
+
top: 0;
|
|
10
|
+
width: 100%;
|
|
11
|
+
height: 100%;
|
|
12
|
+
background-color: #fff;
|
|
13
|
+
transform: translate(100%, 0);
|
|
14
|
+
transition: transform ${ms}ms;
|
|
15
|
+
z-index: 0;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.taro_router > .taro_page.taro_tabbar_page,
|
|
19
|
+
.taro_router > .taro_page.taro_page_show.taro_page_stationed {
|
|
20
|
+
transform: none;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.taro_router > .taro_page.taro_page_show {
|
|
24
|
+
transform: translate(0, 0);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.taro_page_shade,
|
|
28
|
+
.taro_router > .taro_page.taro_page_show.taro_page_stationed:not(.taro_page_shade):not(.taro_tabbar_page):not(:last-child) {
|
|
29
|
+
display: none;
|
|
30
|
+
}`;
|
|
31
|
+
addStyle(css);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* 插入路由相关样式
|
|
35
|
+
*/
|
|
36
|
+
export function loadRouterStyle(usingWindowScroll) {
|
|
37
|
+
const css = `
|
|
38
|
+
.taro_router {
|
|
39
|
+
position: relative;
|
|
40
|
+
width: 100%;
|
|
41
|
+
height: 100%;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.taro_page {
|
|
45
|
+
width: 100%;
|
|
46
|
+
height: 100%;
|
|
47
|
+
${usingWindowScroll ? '' : `
|
|
48
|
+
overflow-x: hidden;
|
|
49
|
+
overflow-y: scroll;
|
|
50
|
+
max-height: 100vh;
|
|
51
|
+
`}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.taro-tabbar__container > .taro-tabbar__panel {
|
|
55
|
+
overflow: hidden;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.taro-tabbar__container > .taro-tabbar__panel > .taro_page.taro_tabbar_page {
|
|
59
|
+
max-height: calc(100vh - var(--taro-tabbar-height) - constant(safe-area-inset-bottom));
|
|
60
|
+
max-height: calc(100vh - var(--taro-tabbar-height) - env(safe-area-inset-bottom));
|
|
61
|
+
}
|
|
62
|
+
`;
|
|
63
|
+
addStyle(css);
|
|
64
|
+
}
|
|
65
|
+
function addStyle(css) {
|
|
66
|
+
if (!css)
|
|
67
|
+
return;
|
|
68
|
+
const style = document.createElement('style');
|
|
69
|
+
style.innerHTML = css;
|
|
70
|
+
document.getElementsByTagName('head')[0].appendChild(style);
|
|
71
|
+
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tarojs/router",
|
|
3
|
-
"version": "3.7.0-alpha.
|
|
3
|
+
"version": "3.7.0-alpha.22",
|
|
4
4
|
"description": "Taro-router",
|
|
5
|
-
"browser": "dist/index.
|
|
6
|
-
"main:h5": "dist/index.js",
|
|
5
|
+
"browser": "dist/index.js",
|
|
6
|
+
"main:h5": "dist/index.esm.js",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
|
-
"module": "dist/index.
|
|
8
|
+
"module": "dist/index.esm.js",
|
|
9
9
|
"typings": "dist/index.d.ts",
|
|
10
10
|
"files": [
|
|
11
11
|
"dist",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"mobile-detect": "^1.4.2",
|
|
28
28
|
"query-string": "^7.1.1",
|
|
29
29
|
"universal-router": "^8.3.0",
|
|
30
|
-
"@tarojs/runtime": "3.7.0-alpha.
|
|
31
|
-
"@tarojs/taro": "3.7.0-alpha.
|
|
30
|
+
"@tarojs/runtime": "3.7.0-alpha.22",
|
|
31
|
+
"@tarojs/taro": "3.7.0-alpha.22"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@rollup/plugin-commonjs": "^20.0.0",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"@types/jest": "^29.4.0",
|
|
37
37
|
"jest": "^29.3.1",
|
|
38
38
|
"jest-cli": "^29.3.1",
|
|
39
|
-
"jest-environment-jsdom": "^29.
|
|
39
|
+
"jest-environment-jsdom": "^29.6.4",
|
|
40
40
|
"jsdom": "^21.1.0",
|
|
41
41
|
"rollup": "^2.79.0",
|
|
42
42
|
"rollup-plugin-node-externals": "^5.0.0",
|
|
@@ -47,7 +47,8 @@
|
|
|
47
47
|
"scripts": {
|
|
48
48
|
"build": "rimraf ./dist && tsc && rollup -c",
|
|
49
49
|
"dev": "tsc -w",
|
|
50
|
-
"test": "jest",
|
|
51
|
-
"test:
|
|
50
|
+
"test": "cross-env NODE_ENV=jest jest",
|
|
51
|
+
"test:ci": "cross-env NODE_ENV=jest jest --ci",
|
|
52
|
+
"test:dev": "cross-env NODE_ENV=jest jest --watch"
|
|
52
53
|
}
|
|
53
54
|
}
|
package/dist/animation.d.ts
DELETED
package/dist/animation.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 插入页面动画需要的样式
|
|
3
|
-
*/
|
|
4
|
-
export function loadAnimateStyle(ms = 300) {
|
|
5
|
-
const css = `
|
|
6
|
-
.taro_router .taro_page {
|
|
7
|
-
position: absolute;
|
|
8
|
-
left: 0;
|
|
9
|
-
top: 0;
|
|
10
|
-
width: 100%;
|
|
11
|
-
height: 100%;
|
|
12
|
-
background-color: #fff;
|
|
13
|
-
transform: translate(100%, 0);
|
|
14
|
-
transition: transform ${ms}ms;
|
|
15
|
-
z-index: 0;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
.taro_router .taro_page.taro_tabbar_page,
|
|
19
|
-
.taro_router .taro_page.taro_page_show.taro_page_stationed {
|
|
20
|
-
transform: none;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
.taro_router .taro_page.taro_page_show {
|
|
24
|
-
transform: translate(0, 0);
|
|
25
|
-
}`;
|
|
26
|
-
const style = document.createElement('style');
|
|
27
|
-
style.innerHTML = css;
|
|
28
|
-
document.getElementsByTagName('head')[0].appendChild(style);
|
|
29
|
-
}
|