@tarojs/router 3.7.0-alpha.7 → 3.7.0-beta.1
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.cjs.js +67 -62
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +67 -62
- package/dist/index.esm.js.map +1 -1
- package/dist/router/index.js +2 -2
- package/dist/router/page.js +4 -0
- package/dist/router/spa.js +3 -1
- package/dist/style.js +0 -1
- package/package.json +3 -3
package/dist/index.cjs.js
CHANGED
|
@@ -41,65 +41,6 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
// export const removeLeadingSlash = (str = '') => str.replace(/^\.?\//, '')
|
|
45
|
-
// export const removeTrailingSearch = (str = '') => str.replace(/\?[\s\S]*$/, '')
|
|
46
|
-
const addLeadingSlash = (url = '') => (url.charAt(0) === '/' ? url : '/' + url);
|
|
47
|
-
const hasBasename = (path = '', prefix = '') => new RegExp('^' + prefix + '(\\/|\\?|#|$)', 'i').test(path) || path === prefix;
|
|
48
|
-
const stripBasename = (path = '', prefix = '') => hasBasename(path, prefix) ? path.substring(prefix.length) : path;
|
|
49
|
-
const stripTrailing = (str = '') => str.replace(/[?#][\s\S]*$/, '');
|
|
50
|
-
const getHomePage = (path = '', basename = '', customRoutes = {}, entryPagePath = '') => {
|
|
51
|
-
var _a;
|
|
52
|
-
const routePath = addLeadingSlash(stripBasename(path, basename));
|
|
53
|
-
const alias = ((_a = Object.entries(customRoutes).find(([key]) => key === routePath)) === null || _a === void 0 ? void 0 : _a[1]) || routePath;
|
|
54
|
-
return entryPagePath || (typeof alias === 'string' ? alias : alias[0]) || basename;
|
|
55
|
-
};
|
|
56
|
-
const getCurrentPage = (routerMode = 'hash', basename = '/') => {
|
|
57
|
-
const pagePath = routerMode === 'hash'
|
|
58
|
-
? location.hash.slice(1).split('?')[0]
|
|
59
|
-
: location.pathname;
|
|
60
|
-
return addLeadingSlash(stripBasename(pagePath, basename));
|
|
61
|
-
};
|
|
62
|
-
class RoutesAlias {
|
|
63
|
-
constructor() {
|
|
64
|
-
this.conf = [];
|
|
65
|
-
this.getConfig = (url = '') => {
|
|
66
|
-
const customRoute = this.conf.filter((arr) => {
|
|
67
|
-
return arr.includes(url);
|
|
68
|
-
});
|
|
69
|
-
return customRoute[0];
|
|
70
|
-
};
|
|
71
|
-
this.getOrigin = (url = '') => {
|
|
72
|
-
var _a;
|
|
73
|
-
return ((_a = this.getConfig(url)) === null || _a === void 0 ? void 0 : _a[0]) || url;
|
|
74
|
-
};
|
|
75
|
-
this.getAlias = (url = '') => {
|
|
76
|
-
var _a;
|
|
77
|
-
return ((_a = this.getConfig(url)) === null || _a === void 0 ? void 0 : _a[1]) || url;
|
|
78
|
-
};
|
|
79
|
-
this.getAll = (url = '') => {
|
|
80
|
-
return this.conf
|
|
81
|
-
.filter((arr) => arr.includes(url))
|
|
82
|
-
.reduceRight((p, a) => {
|
|
83
|
-
p.unshift(a[1]);
|
|
84
|
-
return p;
|
|
85
|
-
}, []);
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
set(customRoutes = {}) {
|
|
89
|
-
for (let key in customRoutes) {
|
|
90
|
-
const path = customRoutes[key];
|
|
91
|
-
key = addLeadingSlash(key);
|
|
92
|
-
if (typeof path === 'string') {
|
|
93
|
-
this.conf.push([key, addLeadingSlash(path)]);
|
|
94
|
-
}
|
|
95
|
-
else if ((path === null || path === void 0 ? void 0 : path.length) > 0) {
|
|
96
|
-
this.conf.push(...path.map(p => [key, addLeadingSlash(p)]));
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
const routesAlias = new RoutesAlias();
|
|
102
|
-
|
|
103
44
|
class RouterConfig {
|
|
104
45
|
static set config(e) {
|
|
105
46
|
this.__config = e;
|
|
@@ -118,7 +59,7 @@ class RouterConfig {
|
|
|
118
59
|
}
|
|
119
60
|
static get customRoutes() { return this.router.customRoutes || {}; }
|
|
120
61
|
static isPage(url = '') {
|
|
121
|
-
return this.pages.findIndex(e =>
|
|
62
|
+
return this.pages.findIndex(e => prependBasename(e) === url) !== -1;
|
|
122
63
|
}
|
|
123
64
|
}
|
|
124
65
|
|
|
@@ -302,6 +243,65 @@ class Stacks {
|
|
|
302
243
|
}
|
|
303
244
|
const stacks = new Stacks();
|
|
304
245
|
|
|
246
|
+
// export const removeLeadingSlash = (str = '') => str.replace(/^\.?\//, '')
|
|
247
|
+
// export const removeTrailingSearch = (str = '') => str.replace(/\?[\s\S]*$/, '')
|
|
248
|
+
const addLeadingSlash = (url = '') => (url.charAt(0) === '/' ? url : '/' + url);
|
|
249
|
+
const hasBasename = (path = '', prefix = '') => new RegExp('^' + prefix + '(\\/|\\?|#|$)', 'i').test(path) || path === prefix;
|
|
250
|
+
const stripBasename = (path = '', prefix = '') => hasBasename(path, prefix) ? path.substring(prefix.length) : path;
|
|
251
|
+
const stripTrailing = (str = '') => str.replace(/[?#][\s\S]*$/, '');
|
|
252
|
+
const getHomePage = (path = '', basename = '', customRoutes = {}, entryPagePath = '') => {
|
|
253
|
+
var _a;
|
|
254
|
+
const routePath = addLeadingSlash(stripBasename(path, basename));
|
|
255
|
+
const alias = ((_a = Object.entries(customRoutes).find(([key]) => key === routePath)) === null || _a === void 0 ? void 0 : _a[1]) || routePath;
|
|
256
|
+
return entryPagePath || (typeof alias === 'string' ? alias : alias[0]) || basename;
|
|
257
|
+
};
|
|
258
|
+
const getCurrentPage = (routerMode = 'hash', basename = '/') => {
|
|
259
|
+
const pagePath = routerMode === 'hash'
|
|
260
|
+
? location.hash.slice(1).split('?')[0]
|
|
261
|
+
: location.pathname;
|
|
262
|
+
return addLeadingSlash(stripBasename(pagePath, basename));
|
|
263
|
+
};
|
|
264
|
+
class RoutesAlias {
|
|
265
|
+
constructor() {
|
|
266
|
+
this.conf = [];
|
|
267
|
+
this.getConfig = (url = '') => {
|
|
268
|
+
const customRoute = this.conf.filter((arr) => {
|
|
269
|
+
return arr.includes(url);
|
|
270
|
+
});
|
|
271
|
+
return customRoute[0];
|
|
272
|
+
};
|
|
273
|
+
this.getOrigin = (url = '') => {
|
|
274
|
+
var _a;
|
|
275
|
+
return ((_a = this.getConfig(url)) === null || _a === void 0 ? void 0 : _a[0]) || url;
|
|
276
|
+
};
|
|
277
|
+
this.getAlias = (url = '') => {
|
|
278
|
+
var _a;
|
|
279
|
+
return ((_a = this.getConfig(url)) === null || _a === void 0 ? void 0 : _a[1]) || url;
|
|
280
|
+
};
|
|
281
|
+
this.getAll = (url = '') => {
|
|
282
|
+
return this.conf
|
|
283
|
+
.filter((arr) => arr.includes(url))
|
|
284
|
+
.reduceRight((p, a) => {
|
|
285
|
+
p.unshift(a[1]);
|
|
286
|
+
return p;
|
|
287
|
+
}, []);
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
set(customRoutes = {}) {
|
|
291
|
+
for (let key in customRoutes) {
|
|
292
|
+
const path = customRoutes[key];
|
|
293
|
+
key = addLeadingSlash(key);
|
|
294
|
+
if (typeof path === 'string') {
|
|
295
|
+
this.conf.push([key, addLeadingSlash(path)]);
|
|
296
|
+
}
|
|
297
|
+
else if ((path === null || path === void 0 ? void 0 : path.length) > 0) {
|
|
298
|
+
this.conf.push(...path.map(p => [key, addLeadingSlash(p)]));
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
const routesAlias = new RoutesAlias();
|
|
304
|
+
|
|
305
305
|
function processNavigateUrl(option) {
|
|
306
306
|
var _a;
|
|
307
307
|
const pathPieces = history.parsePath(option.url);
|
|
@@ -505,7 +505,6 @@ function loadAnimateStyle(ms = 300) {
|
|
|
505
505
|
function loadRouterStyle(usingWindowScroll) {
|
|
506
506
|
const css = `
|
|
507
507
|
.taro_router {
|
|
508
|
-
overflow: hidden;
|
|
509
508
|
position: relative;
|
|
510
509
|
width: 100%;
|
|
511
510
|
height: 100%;
|
|
@@ -1012,6 +1011,7 @@ class PageHandler {
|
|
|
1012
1011
|
var _a, _b;
|
|
1013
1012
|
this.unloadTimer = null;
|
|
1014
1013
|
(_b = (_a = this.lastUnloadPage) === null || _a === void 0 ? void 0 : _a.onUnload) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
1014
|
+
runtime.eventCenter.trigger('__taroPageOnShowAfterDestroyed');
|
|
1015
1015
|
}, this.animationDuration);
|
|
1016
1016
|
}
|
|
1017
1017
|
else {
|
|
@@ -1019,6 +1019,9 @@ class PageHandler {
|
|
|
1019
1019
|
pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.remove('taro_page_stationed');
|
|
1020
1020
|
pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.remove('taro_page_show');
|
|
1021
1021
|
(_c = page === null || page === void 0 ? void 0 : page.onUnload) === null || _c === void 0 ? void 0 : _c.call(page);
|
|
1022
|
+
setTimeout(() => {
|
|
1023
|
+
runtime.eventCenter.trigger('__taroPageOnShowAfterDestroyed');
|
|
1024
|
+
}, 0);
|
|
1022
1025
|
}
|
|
1023
1026
|
if (delta >= 1)
|
|
1024
1027
|
this.unload(stacks.last, delta);
|
|
@@ -1248,7 +1251,9 @@ function createRouter(app, config, framework) {
|
|
|
1248
1251
|
if (currentPage !== stacks.getItem(prevIndex)) {
|
|
1249
1252
|
handler.unload(currentPage, delta, prevIndex > -1);
|
|
1250
1253
|
if (prevIndex > -1) {
|
|
1251
|
-
|
|
1254
|
+
runtime.eventCenter.once('__taroPageOnShowAfterDestroyed', () => {
|
|
1255
|
+
handler.show(stacks.getItem(prevIndex), pageConfig, prevIndex);
|
|
1256
|
+
});
|
|
1252
1257
|
}
|
|
1253
1258
|
else {
|
|
1254
1259
|
shouldLoad = true;
|