@tarojs/router 4.0.0-beta.82 → 4.0.0-beta.83
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/LICENSE +1 -8
- package/dist/api.d.ts +6 -7
- package/dist/api.js +4 -16
- package/dist/events/resize.d.ts +2 -3
- package/dist/events/scroll.d.ts +2 -3
- package/dist/history.d.ts +10 -8
- package/dist/index.cjs.js +84 -68
- package/dist/index.d.ts +9 -10
- package/dist/index.esm.js +82 -66
- package/dist/navigationBar.d.ts +2 -3
- package/dist/router/index.d.ts +3 -4
- package/dist/router/index.js +3 -2
- package/dist/router/mpa.d.ts +4 -5
- package/dist/router/mpa.js +2 -2
- package/dist/router/multi-page.d.ts +7 -8
- package/dist/router/navigation-bar.d.ts +3 -3
- package/dist/router/navigation-bar.js +6 -6
- package/dist/router/page.d.ts +11 -10
- package/dist/router/page.js +26 -14
- package/dist/router/spa.d.ts +4 -5
- package/dist/router/spa.js +36 -23
- package/dist/router/stack.d.ts +2 -2
- package/dist/style.d.ts +4 -5
- package/dist/style.js +6 -4
- package/dist/tabbar.d.ts +2 -3
- package/dist/utils/index.d.ts +2 -3
- package/dist/utils/navigate.d.ts +6 -7
- package/package.json +18 -29
- package/dist/index.cjs.d.ts +0 -66
- package/dist/index.esm.d.ts +0 -66
package/dist/index.esm.js
CHANGED
|
@@ -14,7 +14,8 @@ import UniversalRouter from 'universal-router';
|
|
|
14
14
|
function loadAnimateStyle(ms = 300) {
|
|
15
15
|
const css = `
|
|
16
16
|
body {
|
|
17
|
-
|
|
17
|
+
/* 防止 iOS 页面滚动 */
|
|
18
|
+
overflow: hidden;
|
|
18
19
|
}
|
|
19
20
|
.taro_router > .taro_page {
|
|
20
21
|
position: absolute;
|
|
@@ -71,8 +72,9 @@ ${enableTabBar ? `
|
|
|
71
72
|
}
|
|
72
73
|
|
|
73
74
|
` : ''}
|
|
74
|
-
.taro_page_shade,
|
|
75
|
-
.
|
|
75
|
+
.taro_page_shade:has(+.taro_page_stationed),
|
|
76
|
+
.taro_page_shade.taro_tabbar_page,
|
|
77
|
+
.taro_router > .taro_page.taro_page_show.taro_page_stationed:not(.taro_page_shade):not(.taro_tabbar_page):not(:last-child):has(+.taro_page_stationed) {
|
|
76
78
|
display: none;
|
|
77
79
|
}
|
|
78
80
|
`;
|
|
@@ -140,7 +142,7 @@ function loadNavigationBarStyle() {
|
|
|
140
142
|
to {
|
|
141
143
|
transform: rotate(360deg);
|
|
142
144
|
}
|
|
143
|
-
}
|
|
145
|
+
}
|
|
144
146
|
|
|
145
147
|
.taro-navigation-bar-no-icon > .taro-navigation-bar-home {
|
|
146
148
|
display: none;
|
|
@@ -262,8 +264,9 @@ class RouterConfig {
|
|
|
262
264
|
return this.router.mode || 'hash';
|
|
263
265
|
}
|
|
264
266
|
static get customRoutes() { return this.router.customRoutes || {}; }
|
|
267
|
+
// 这个方法不考虑 basename 和 customRoutes,只判断原始的 url 是否在 pages 中
|
|
265
268
|
static isPage(url = '') {
|
|
266
|
-
return this.pages.findIndex(e =>
|
|
269
|
+
return this.pages.findIndex(e => addLeadingSlash(e) === url) !== -1;
|
|
267
270
|
}
|
|
268
271
|
}
|
|
269
272
|
|
|
@@ -532,13 +535,14 @@ function processNavigateUrl(option) {
|
|
|
532
535
|
const parts = routesAlias.getOrigin(history.location.pathname).split('/');
|
|
533
536
|
parts.pop();
|
|
534
537
|
pathPieces.pathname.split('/').forEach((item) => {
|
|
535
|
-
if (item === '.')
|
|
538
|
+
if (item === '.')
|
|
536
539
|
return;
|
|
537
|
-
}
|
|
538
540
|
item === '..' ? parts.pop() : parts.push(item);
|
|
539
541
|
});
|
|
540
542
|
pathPieces.pathname = parts.join('/');
|
|
541
543
|
}
|
|
544
|
+
// 确保是 / 开头的路径
|
|
545
|
+
pathPieces.pathname = addLeadingSlash(pathPieces.pathname);
|
|
542
546
|
// 处理自定义路由
|
|
543
547
|
pathPieces.pathname = routesAlias.getAlias(addLeadingSlash(pathPieces.pathname));
|
|
544
548
|
// 处理 basename
|
|
@@ -568,21 +572,8 @@ function navigate(option, method) {
|
|
|
568
572
|
if ('url' in option) {
|
|
569
573
|
const pathPieces = processNavigateUrl(option);
|
|
570
574
|
const state = { timestamp: Date.now() };
|
|
571
|
-
if (pathPieces.pathname) {
|
|
572
|
-
const originPath = routesAlias.getOrigin(pathPieces.pathname);
|
|
573
|
-
if (!RouterConfig.isPage(addLeadingSlash(originPath)) && !RouterConfig.isPage(addLeadingSlash(pathPieces.pathname))) {
|
|
574
|
-
const res = { errMsg: `${method}:fail page ${originPath} is not found` };
|
|
575
|
-
fail === null || fail === void 0 ? void 0 : fail(res);
|
|
576
|
-
complete === null || complete === void 0 ? void 0 : complete(res);
|
|
577
|
-
if (fail || complete) {
|
|
578
|
-
return resolve(res);
|
|
579
|
-
}
|
|
580
|
-
else {
|
|
581
|
-
return reject(res);
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
575
|
if (method === 'navigateTo') {
|
|
576
|
+
// Note: 由于 spa 会针对弱网情况下,短时间内多次跳转同一个页面跳转加了锁,后续如果有用户反馈返回无效,那可能是这个问题
|
|
586
577
|
history.push(pathPieces, state);
|
|
587
578
|
}
|
|
588
579
|
else if (method === 'redirectTo' || method === 'switchTab') {
|
|
@@ -852,8 +843,8 @@ const launchStampId$1 = createStampId$1();
|
|
|
852
843
|
* - 不支持路由动画
|
|
853
844
|
*/
|
|
854
845
|
function createMultiRouter(history, app, config, framework) {
|
|
855
|
-
var _a, _b, _c, _d, _e, _f;
|
|
856
846
|
return __awaiter(this, void 0, void 0, function* () {
|
|
847
|
+
var _a, _b, _c, _d, _e, _f;
|
|
857
848
|
if (typeof app.onUnhandledRejection === 'function') {
|
|
858
849
|
window.addEventListener('unhandledrejection', app.onUnhandledRejection);
|
|
859
850
|
}
|
|
@@ -861,7 +852,7 @@ function createMultiRouter(history, app, config, framework) {
|
|
|
861
852
|
RouterConfig.config = config;
|
|
862
853
|
const handler = new MultiPageHandler(config, history);
|
|
863
854
|
const launchParam = {
|
|
864
|
-
path: config.pageName,
|
|
855
|
+
path: config.pageName, // 多页面模式没新开一个页面相当于重启,所以直接使用当前页面路径
|
|
865
856
|
query: handler.getQuery(launchStampId$1),
|
|
866
857
|
scene: 0,
|
|
867
858
|
shareTicket: '',
|
|
@@ -940,7 +931,7 @@ class NavigationBarHandler {
|
|
|
940
931
|
});
|
|
941
932
|
}
|
|
942
933
|
toHomeFn() {
|
|
943
|
-
reLaunch({ url: this.pageContext.
|
|
934
|
+
reLaunch({ url: this.pageContext.originHomePage });
|
|
944
935
|
}
|
|
945
936
|
backFn() {
|
|
946
937
|
navigateBack();
|
|
@@ -989,7 +980,7 @@ class NavigationBarHandler {
|
|
|
989
980
|
this.setNavigationLoading();
|
|
990
981
|
}
|
|
991
982
|
setCacheValue() {
|
|
992
|
-
const currentPage = this.pageContext.
|
|
983
|
+
const currentPage = this.pageContext.originPathname;
|
|
993
984
|
if (typeof this.cache[currentPage] !== 'object') {
|
|
994
985
|
this.cache[currentPage] = {};
|
|
995
986
|
}
|
|
@@ -1020,7 +1011,7 @@ class NavigationBarHandler {
|
|
|
1020
1011
|
var _a;
|
|
1021
1012
|
if (!this.navigationBarElement)
|
|
1022
1013
|
return;
|
|
1023
|
-
const currentPage = this.pageContext.
|
|
1014
|
+
const currentPage = this.pageContext.originPathname;
|
|
1024
1015
|
let isShow;
|
|
1025
1016
|
if (typeof show === 'boolean') {
|
|
1026
1017
|
isShow = show;
|
|
@@ -1045,7 +1036,7 @@ class NavigationBarHandler {
|
|
|
1045
1036
|
var _a, _b, _c;
|
|
1046
1037
|
if (!this.navigationBarElement)
|
|
1047
1038
|
return;
|
|
1048
|
-
const currentPage = this.pageContext.
|
|
1039
|
+
const currentPage = this.pageContext.originPathname;
|
|
1049
1040
|
let color;
|
|
1050
1041
|
if (typeof backgroundColor === 'string') {
|
|
1051
1042
|
color = backgroundColor;
|
|
@@ -1069,7 +1060,7 @@ class NavigationBarHandler {
|
|
|
1069
1060
|
var _a, _b, _c;
|
|
1070
1061
|
if (!this.navigationBarElement)
|
|
1071
1062
|
return;
|
|
1072
|
-
const currentPage = this.pageContext.
|
|
1063
|
+
const currentPage = this.pageContext.originPathname;
|
|
1073
1064
|
let color;
|
|
1074
1065
|
if (typeof fontColor === 'string') {
|
|
1075
1066
|
color = fontColor;
|
|
@@ -1091,7 +1082,7 @@ class NavigationBarHandler {
|
|
|
1091
1082
|
}
|
|
1092
1083
|
setTitle(title) {
|
|
1093
1084
|
var _a, _b, _c;
|
|
1094
|
-
const currentPage = this.pageContext.
|
|
1085
|
+
const currentPage = this.pageContext.originPathname;
|
|
1095
1086
|
let proceedTitle;
|
|
1096
1087
|
if (typeof title === 'string') {
|
|
1097
1088
|
proceedTitle = title;
|
|
@@ -1172,6 +1163,7 @@ class PageHandler {
|
|
|
1172
1163
|
this.defaultAnimation = { duration: 300, delay: 50 };
|
|
1173
1164
|
this.config = config;
|
|
1174
1165
|
this.homePage = getHomePage(this.routes[0].path, this.basename, this.customRoutes, this.config.entryPagePath);
|
|
1166
|
+
this.originHomePage = this.config.entryPagePath || this.routes[0].path || this.basename;
|
|
1175
1167
|
this.mount();
|
|
1176
1168
|
this.navigationBarHandler = new NavigationBarHandler(this);
|
|
1177
1169
|
}
|
|
@@ -1205,14 +1197,14 @@ class PageHandler {
|
|
|
1205
1197
|
}
|
|
1206
1198
|
set pathname(p) { this.router.pathname = p; }
|
|
1207
1199
|
get pathname() { return this.router.pathname; }
|
|
1200
|
+
// Note: 把 pathname 转换为原始路径,主要是处理 customRoutes 和 basename
|
|
1201
|
+
get originPathname() { return routesAlias.getOrigin(addLeadingSlash(stripBasename(this.pathname, this.basename))); }
|
|
1208
1202
|
get basename() { return this.router.basename || ''; }
|
|
1209
1203
|
get pageConfig() {
|
|
1210
|
-
const routePath = addLeadingSlash(stripBasename(this.pathname, this.basename));
|
|
1211
1204
|
const homePage = addLeadingSlash(this.homePage);
|
|
1212
1205
|
return this.routes.find(r => {
|
|
1213
|
-
var _a;
|
|
1214
1206
|
const pagePath = addLeadingSlash(r.path);
|
|
1215
|
-
return [pagePath, homePage].includes(
|
|
1207
|
+
return [pagePath, homePage].includes(this.originPathname);
|
|
1216
1208
|
});
|
|
1217
1209
|
}
|
|
1218
1210
|
isTabBar(pathname) {
|
|
@@ -1402,24 +1394,35 @@ class PageHandler {
|
|
|
1402
1394
|
});
|
|
1403
1395
|
}
|
|
1404
1396
|
}
|
|
1405
|
-
hide(page) {
|
|
1406
|
-
var _a;
|
|
1397
|
+
hide(page, animation = false) {
|
|
1398
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1407
1399
|
if (!page)
|
|
1408
1400
|
return;
|
|
1409
1401
|
// NOTE: 修复多页并发问题,此处可能因为路由跳转过快,执行时页面可能还没有创建成功
|
|
1410
1402
|
const pageEl = this.getPageContainer(page);
|
|
1411
1403
|
if (pageEl) {
|
|
1412
|
-
if (
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1404
|
+
if (animation) {
|
|
1405
|
+
if (this.hideTimer) {
|
|
1406
|
+
clearTimeout(this.hideTimer);
|
|
1407
|
+
this.hideTimer = null;
|
|
1408
|
+
(_c = (_b = (_a = this.lastHidePage) === null || _a === void 0 ? void 0 : _a.classList) === null || _b === void 0 ? void 0 : _b.add) === null || _c === void 0 ? void 0 : _c.call(_b, 'taro_page_shade');
|
|
1409
|
+
}
|
|
1410
|
+
this.lastHidePage = pageEl;
|
|
1411
|
+
this.hideTimer = setTimeout(() => {
|
|
1412
|
+
this.hideTimer = null;
|
|
1413
|
+
pageEl.classList.add('taro_page_shade');
|
|
1414
|
+
}, this.animationDuration + this.animationDelay);
|
|
1415
|
+
(_d = page.onHide) === null || _d === void 0 ? void 0 : _d.call(page);
|
|
1416
1416
|
}
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1417
|
+
else {
|
|
1418
|
+
if (this.hideTimer) {
|
|
1419
|
+
clearTimeout(this.hideTimer);
|
|
1420
|
+
this.hideTimer = null;
|
|
1421
|
+
(_g = (_f = (_e = this.lastHidePage) === null || _e === void 0 ? void 0 : _e.classList) === null || _f === void 0 ? void 0 : _f.add) === null || _g === void 0 ? void 0 : _g.call(_f, 'taro_page_shade');
|
|
1422
|
+
}
|
|
1420
1423
|
pageEl.classList.add('taro_page_shade');
|
|
1421
|
-
|
|
1422
|
-
|
|
1424
|
+
this.lastHidePage = pageEl;
|
|
1425
|
+
}
|
|
1423
1426
|
}
|
|
1424
1427
|
else {
|
|
1425
1428
|
setTimeout(() => this.hide(page), 0);
|
|
@@ -1490,6 +1493,10 @@ function createRouter(history, app, config, framework) {
|
|
|
1490
1493
|
}
|
|
1491
1494
|
RouterConfig.config = config;
|
|
1492
1495
|
const handler = new PageHandler(config, history);
|
|
1496
|
+
// Note: 弱网情况下,快速切换 tab,会造成同个页面实例被多次挂在到页面上,原因是资源请求是异步的,短时间内发起多个请求,
|
|
1497
|
+
// 会在资源加载完成后,同时走到挂载的逻辑,造成 pageStampId 更新不及时,两个 page 的Id 相同,后面很多操作是通过 getElementById 来进行的
|
|
1498
|
+
// 所以需要加一个锁来应对这个情况
|
|
1499
|
+
const pageLock = {};
|
|
1493
1500
|
routesAlias.set(handler.router.customRoutes);
|
|
1494
1501
|
const basename = handler.router.basename;
|
|
1495
1502
|
const routes = handler.routes.map(route => {
|
|
@@ -1511,29 +1518,35 @@ function createRouter(history, app, config, framework) {
|
|
|
1511
1518
|
eventCenter.trigger('__taroRouterLaunch', launchParam);
|
|
1512
1519
|
(_a = app.onLaunch) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
|
|
1513
1520
|
app.onError && window.addEventListener('error', e => { var _a; return (_a = app.onError) === null || _a === void 0 ? void 0 : _a.call(app, e.message); });
|
|
1514
|
-
const render = (
|
|
1515
|
-
var
|
|
1516
|
-
|
|
1517
|
-
|
|
1521
|
+
const render = (_c) => __awaiter(this, [_c], void 0, function* ({ location, action }) {
|
|
1522
|
+
var _d, _e, _f, _g, _h, _j, _k, _l;
|
|
1523
|
+
// Note: 由于下面有异步加载操作 先不要在这里去设置 handler.pathname
|
|
1524
|
+
const currentPathname = decodeURI(location.pathname);
|
|
1525
|
+
if ((_d = window.__taroAppConfig) === null || _d === void 0 ? void 0 : _d.usingWindowScroll)
|
|
1518
1526
|
window.scrollTo(0, 0);
|
|
1519
1527
|
eventCenter.trigger('__taroRouterChange', {
|
|
1520
1528
|
toLocation: {
|
|
1521
|
-
path:
|
|
1529
|
+
path: currentPathname
|
|
1522
1530
|
}
|
|
1523
1531
|
});
|
|
1524
|
-
let element, params;
|
|
1532
|
+
let element, context, params;
|
|
1533
|
+
const routerPath = handler.router.forcePath || currentPathname;
|
|
1534
|
+
pageLock[routerPath] = typeof pageLock[routerPath] === 'number' ? pageLock[routerPath] + 1 : 1;
|
|
1535
|
+
const currentLock = pageLock[routerPath];
|
|
1536
|
+
let postLock;
|
|
1525
1537
|
try {
|
|
1526
|
-
const result = yield router.resolve(
|
|
1527
|
-
[element, , params] = yield Promise.all(result);
|
|
1538
|
+
const result = yield router.resolve(routerPath);
|
|
1539
|
+
[element, context, params] = yield Promise.all(result);
|
|
1540
|
+
postLock = pageLock[routerPath];
|
|
1528
1541
|
}
|
|
1529
1542
|
catch (error) {
|
|
1530
1543
|
if (error.status === 404) {
|
|
1531
1544
|
const notFoundEvent = {
|
|
1532
1545
|
isEntryPage: stacks.length === 0,
|
|
1533
|
-
path:
|
|
1546
|
+
path: currentPathname,
|
|
1534
1547
|
query: handler.getQuery(createStampId()),
|
|
1535
1548
|
};
|
|
1536
|
-
(
|
|
1549
|
+
(_e = app.onPageNotFound) === null || _e === void 0 ? void 0 : _e.call(app, notFoundEvent);
|
|
1537
1550
|
eventCenter.trigger('__taroRouterNotFound', notFoundEvent);
|
|
1538
1551
|
}
|
|
1539
1552
|
else if (/Loading hot update .* failed./.test(error.message)) {
|
|
@@ -1544,13 +1557,16 @@ function createRouter(history, app, config, framework) {
|
|
|
1544
1557
|
throw error;
|
|
1545
1558
|
}
|
|
1546
1559
|
}
|
|
1547
|
-
if (!element)
|
|
1560
|
+
if (!element || currentLock !== postLock)
|
|
1548
1561
|
return;
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
let
|
|
1562
|
+
// Note: 异步结束后,在设置 handler.pathname
|
|
1563
|
+
// context.pathname 在 universal-router 被处理过了,是发起资源请求的时候传入的 pathname,即 await router.resolve(routerPath) 这个 routerPath
|
|
1564
|
+
handler.pathname = context.pathname;
|
|
1565
|
+
const { pathname, pageConfig } = handler;
|
|
1566
|
+
let enablePullDownRefresh = ((_f = config === null || config === void 0 ? void 0 : config.window) === null || _f === void 0 ? void 0 : _f.enablePullDownRefresh) || false;
|
|
1567
|
+
let navigationStyle = ((_g = config === null || config === void 0 ? void 0 : config.window) === null || _g === void 0 ? void 0 : _g.navigationStyle) || 'default';
|
|
1568
|
+
let navigationBarTextStyle = ((_h = config === null || config === void 0 ? void 0 : config.window) === null || _h === void 0 ? void 0 : _h.navigationBarTextStyle) || 'white';
|
|
1569
|
+
let navigationBarBackgroundColor = ((_j = config === null || config === void 0 ? void 0 : config.window) === null || _j === void 0 ? void 0 : _j.navigationBarBackgroundColor) || '#000000';
|
|
1554
1570
|
if (pageConfig) {
|
|
1555
1571
|
if (typeof pageConfig.enablePullDownRefresh === 'boolean') {
|
|
1556
1572
|
enablePullDownRefresh = pageConfig.enablePullDownRefresh;
|
|
@@ -1567,8 +1583,7 @@ function createRouter(history, app, config, framework) {
|
|
|
1567
1583
|
}
|
|
1568
1584
|
eventCenter.trigger('__taroSetNavigationStyle', navigationStyle, navigationBarTextStyle, navigationBarBackgroundColor);
|
|
1569
1585
|
const currentPage = Current.page;
|
|
1570
|
-
const
|
|
1571
|
-
const methodName = (_j = stacks.method) !== null && _j !== void 0 ? _j : '';
|
|
1586
|
+
const methodName = (_k = stacks.method) !== null && _k !== void 0 ? _k : '';
|
|
1572
1587
|
const cacheTabs = stacks.getTabs();
|
|
1573
1588
|
let shouldLoad = false;
|
|
1574
1589
|
stacks.method = '';
|
|
@@ -1583,10 +1598,11 @@ function createRouter(history, app, config, framework) {
|
|
|
1583
1598
|
}
|
|
1584
1599
|
shouldLoad = true;
|
|
1585
1600
|
}
|
|
1586
|
-
else if (currentPage && handler.isTabBar(
|
|
1601
|
+
else if (currentPage && handler.isTabBar(pathname)) {
|
|
1587
1602
|
if (handler.isSamePage(currentPage))
|
|
1588
1603
|
return;
|
|
1589
1604
|
if (handler.isTabBar(currentPage.path)) {
|
|
1605
|
+
// NOTE: 从 tabBar 页面切换到 tabBar 页面
|
|
1590
1606
|
handler.hide(currentPage);
|
|
1591
1607
|
stacks.pushTab(currentPage.path.split('?')[0]);
|
|
1592
1608
|
}
|
|
@@ -1600,8 +1616,8 @@ function createRouter(history, app, config, framework) {
|
|
|
1600
1616
|
handler.unload(currentPage, stacks.length, true);
|
|
1601
1617
|
}
|
|
1602
1618
|
}
|
|
1603
|
-
if (cacheTabs[
|
|
1604
|
-
stacks.popTab(
|
|
1619
|
+
if (cacheTabs[pathname]) {
|
|
1620
|
+
stacks.popTab(pathname);
|
|
1605
1621
|
return handler.show(stacks.getItem(0), pageConfig, 0);
|
|
1606
1622
|
}
|
|
1607
1623
|
shouldLoad = true;
|
|
@@ -1630,11 +1646,11 @@ function createRouter(history, app, config, framework) {
|
|
|
1630
1646
|
shouldLoad = true;
|
|
1631
1647
|
}
|
|
1632
1648
|
else if (action === 'PUSH') {
|
|
1633
|
-
handler.hide(currentPage);
|
|
1649
|
+
handler.hide(currentPage, true);
|
|
1634
1650
|
shouldLoad = true;
|
|
1635
1651
|
}
|
|
1636
1652
|
if (shouldLoad || stacks.length < 1) {
|
|
1637
|
-
const el = (
|
|
1653
|
+
const el = (_l = element.default) !== null && _l !== void 0 ? _l : element;
|
|
1638
1654
|
const loadConfig = Object.assign({}, pageConfig);
|
|
1639
1655
|
const stacksIndex = stacks.length;
|
|
1640
1656
|
delete loadConfig['path'];
|
package/dist/navigationBar.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import { MpaRouterConfig, SpaRouterConfig } from '../types/router';
|
|
2
|
-
declare function initNavigationBar(config: SpaRouterConfig | MpaRouterConfig, container: HTMLElement): void;
|
|
3
|
-
export { initNavigationBar };
|
|
1
|
+
import type { MpaRouterConfig, SpaRouterConfig } from '../types/router';
|
|
2
|
+
export declare function initNavigationBar(config: SpaRouterConfig | MpaRouterConfig, container: HTMLElement): void;
|
package/dist/router/index.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { MpaRouterConfig, SpaRouterConfig } from '../../types/router';
|
|
2
|
-
declare class RouterConfig {
|
|
1
|
+
import type { MpaRouterConfig, SpaRouterConfig } from '../../types/router';
|
|
2
|
+
export declare class RouterConfig {
|
|
3
3
|
private static __config;
|
|
4
4
|
static set config(e: SpaRouterConfig | MpaRouterConfig);
|
|
5
5
|
static get config(): SpaRouterConfig | MpaRouterConfig;
|
|
6
6
|
static get pages(): string[];
|
|
7
|
-
static get router(): import("
|
|
7
|
+
static get router(): import("../../types/router").Router;
|
|
8
8
|
static get mode(): "hash" | "browser" | "multi";
|
|
9
9
|
static get customRoutes(): Record<string, string | string[]>;
|
|
10
10
|
static isPage(url?: string): boolean;
|
|
11
11
|
}
|
|
12
|
-
export { RouterConfig };
|
package/dist/router/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { addLeadingSlash } from '@tarojs/runtime';
|
|
2
2
|
|
|
3
3
|
class RouterConfig {
|
|
4
4
|
static set config(e) {
|
|
@@ -17,8 +17,9 @@ class RouterConfig {
|
|
|
17
17
|
return this.router.mode || 'hash';
|
|
18
18
|
}
|
|
19
19
|
static get customRoutes() { return this.router.customRoutes || {}; }
|
|
20
|
+
// 这个方法不考虑 basename 和 customRoutes,只判断原始的 url 是否在 pages 中
|
|
20
21
|
static isPage(url = '') {
|
|
21
|
-
return this.pages.findIndex(e =>
|
|
22
|
+
return this.pages.findIndex(e => addLeadingSlash(e) === url) !== -1;
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
25
|
|
package/dist/router/mpa.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { AppInstance } from '@tarojs/runtime';
|
|
2
|
-
import { History } from
|
|
3
|
-
import { MpaRouterConfig } from '../../types/router';
|
|
1
|
+
import type { AppInstance } from '@tarojs/runtime';
|
|
2
|
+
import type { History } from 'history';
|
|
3
|
+
import type { MpaRouterConfig } from '../../types/router';
|
|
4
4
|
/** Note: 关于多页面应用
|
|
5
5
|
* - 需要配置路由映射(根目录跳转、404 页面……)
|
|
6
6
|
* - app.onPageNotFound 事件不支持
|
|
@@ -8,5 +8,4 @@ import { MpaRouterConfig } from '../../types/router';
|
|
|
8
8
|
* - TabBar 会多次加载
|
|
9
9
|
* - 不支持路由动画
|
|
10
10
|
*/
|
|
11
|
-
declare function createMultiRouter(history: History, app: AppInstance, config: MpaRouterConfig, framework?: string): Promise<void>;
|
|
12
|
-
export { createMultiRouter };
|
|
11
|
+
export declare function createMultiRouter(history: History, app: AppInstance, config: MpaRouterConfig, framework?: string): Promise<void>;
|
package/dist/router/mpa.js
CHANGED
|
@@ -16,8 +16,8 @@ const launchStampId = createStampId();
|
|
|
16
16
|
* - 不支持路由动画
|
|
17
17
|
*/
|
|
18
18
|
function createMultiRouter(history, app, config, framework) {
|
|
19
|
-
var _a, _b, _c, _d, _e, _f;
|
|
20
19
|
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
var _a, _b, _c, _d, _e, _f;
|
|
21
21
|
if (typeof app.onUnhandledRejection === 'function') {
|
|
22
22
|
window.addEventListener('unhandledrejection', app.onUnhandledRejection);
|
|
23
23
|
}
|
|
@@ -25,7 +25,7 @@ function createMultiRouter(history, app, config, framework) {
|
|
|
25
25
|
RouterConfig.config = config;
|
|
26
26
|
const handler = new MultiPageHandler(config, history);
|
|
27
27
|
const launchParam = {
|
|
28
|
-
path: config.pageName,
|
|
28
|
+
path: config.pageName, // 多页面模式没新开一个页面相当于重启,所以直接使用当前页面路径
|
|
29
29
|
query: handler.getQuery(launchStampId),
|
|
30
30
|
scene: 0,
|
|
31
31
|
shareTicket: '',
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { PageInstance } from '@tarojs/runtime';
|
|
2
|
-
import { PageConfig } from '@tarojs/taro';
|
|
3
|
-
import { History } from
|
|
4
|
-
import { MpaRouterConfig, Route } from '../../types/router';
|
|
5
|
-
|
|
1
|
+
import type { PageInstance } from '@tarojs/runtime';
|
|
2
|
+
import type { PageConfig } from '@tarojs/taro';
|
|
3
|
+
import type { History } from 'history';
|
|
4
|
+
import type { MpaRouterConfig, Route } from '../../types/router';
|
|
5
|
+
export default class MultiPageHandler {
|
|
6
6
|
history: History;
|
|
7
7
|
protected config: MpaRouterConfig;
|
|
8
8
|
constructor(config: MpaRouterConfig, history: History);
|
|
9
9
|
get appId(): string;
|
|
10
|
-
get router(): import("
|
|
10
|
+
get router(): import("../../types/router").Router;
|
|
11
11
|
get routerMode(): "hash" | "browser" | "multi";
|
|
12
12
|
get customRoutes(): Record<string, string | string[]>;
|
|
13
13
|
get tabBarList(): import("@tarojs/taro").TabBarItem[];
|
|
@@ -27,8 +27,7 @@ declare class MultiPageHandler {
|
|
|
27
27
|
onReady(page: PageInstance, onLoad?: boolean): void;
|
|
28
28
|
load(page: PageInstance, pageConfig?: Route): void;
|
|
29
29
|
getPageContainer(page?: PageInstance | null): HTMLElement | null;
|
|
30
|
-
getScrollingElement(page?: PageInstance | null):
|
|
30
|
+
getScrollingElement(page?: PageInstance | null): (Window & typeof globalThis) | HTMLElement;
|
|
31
31
|
bindPageEvents(page: PageInstance, config?: Partial<PageConfig>): void;
|
|
32
32
|
triggerRouterChange(): void;
|
|
33
33
|
}
|
|
34
|
-
export { MultiPageHandler as default };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import PageHandler from
|
|
1
|
+
import type PageHandler from './page';
|
|
2
2
|
interface NavigationBarCache {
|
|
3
3
|
backgroundColor?: string;
|
|
4
4
|
fontColor?: string;
|
|
@@ -6,7 +6,7 @@ interface NavigationBarCache {
|
|
|
6
6
|
show?: boolean;
|
|
7
7
|
loading?: boolean;
|
|
8
8
|
}
|
|
9
|
-
|
|
9
|
+
export default class NavigationBarHandler {
|
|
10
10
|
pageContext: PageHandler;
|
|
11
11
|
navigationBarElement: HTMLElement;
|
|
12
12
|
cache: Record<string, NavigationBarCache>;
|
|
@@ -33,4 +33,4 @@ declare class NavigationBarHandler {
|
|
|
33
33
|
fnBtnToggleToNone(): void;
|
|
34
34
|
setNavigationBarVisible(show?: any): void;
|
|
35
35
|
}
|
|
36
|
-
export {
|
|
36
|
+
export {};
|
|
@@ -24,7 +24,7 @@ class NavigationBarHandler {
|
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
26
|
toHomeFn() {
|
|
27
|
-
reLaunch({ url: this.pageContext.
|
|
27
|
+
reLaunch({ url: this.pageContext.originHomePage });
|
|
28
28
|
}
|
|
29
29
|
backFn() {
|
|
30
30
|
navigateBack();
|
|
@@ -73,7 +73,7 @@ class NavigationBarHandler {
|
|
|
73
73
|
this.setNavigationLoading();
|
|
74
74
|
}
|
|
75
75
|
setCacheValue() {
|
|
76
|
-
const currentPage = this.pageContext.
|
|
76
|
+
const currentPage = this.pageContext.originPathname;
|
|
77
77
|
if (typeof this.cache[currentPage] !== 'object') {
|
|
78
78
|
this.cache[currentPage] = {};
|
|
79
79
|
}
|
|
@@ -104,7 +104,7 @@ class NavigationBarHandler {
|
|
|
104
104
|
var _a;
|
|
105
105
|
if (!this.navigationBarElement)
|
|
106
106
|
return;
|
|
107
|
-
const currentPage = this.pageContext.
|
|
107
|
+
const currentPage = this.pageContext.originPathname;
|
|
108
108
|
let isShow;
|
|
109
109
|
if (typeof show === 'boolean') {
|
|
110
110
|
isShow = show;
|
|
@@ -129,7 +129,7 @@ class NavigationBarHandler {
|
|
|
129
129
|
var _a, _b, _c;
|
|
130
130
|
if (!this.navigationBarElement)
|
|
131
131
|
return;
|
|
132
|
-
const currentPage = this.pageContext.
|
|
132
|
+
const currentPage = this.pageContext.originPathname;
|
|
133
133
|
let color;
|
|
134
134
|
if (typeof backgroundColor === 'string') {
|
|
135
135
|
color = backgroundColor;
|
|
@@ -153,7 +153,7 @@ class NavigationBarHandler {
|
|
|
153
153
|
var _a, _b, _c;
|
|
154
154
|
if (!this.navigationBarElement)
|
|
155
155
|
return;
|
|
156
|
-
const currentPage = this.pageContext.
|
|
156
|
+
const currentPage = this.pageContext.originPathname;
|
|
157
157
|
let color;
|
|
158
158
|
if (typeof fontColor === 'string') {
|
|
159
159
|
color = fontColor;
|
|
@@ -175,7 +175,7 @@ class NavigationBarHandler {
|
|
|
175
175
|
}
|
|
176
176
|
setTitle(title) {
|
|
177
177
|
var _a, _b, _c;
|
|
178
|
-
const currentPage = this.pageContext.
|
|
178
|
+
const currentPage = this.pageContext.originPathname;
|
|
179
179
|
let proceedTitle;
|
|
180
180
|
if (typeof title === 'string') {
|
|
181
181
|
proceedTitle = title;
|
package/dist/router/page.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import NavigationBarHandler from
|
|
2
|
-
import { PageInstance } from '@tarojs/runtime';
|
|
3
|
-
import { PageConfig, RouterAnimate } from '@tarojs/taro';
|
|
4
|
-
import { History } from
|
|
5
|
-
import { Route, SpaRouterConfig } from '../../types/router';
|
|
6
|
-
|
|
1
|
+
import NavigationBarHandler from './navigation-bar';
|
|
2
|
+
import type { PageInstance } from '@tarojs/runtime';
|
|
3
|
+
import type { PageConfig, RouterAnimate } from '@tarojs/taro';
|
|
4
|
+
import type { History } from 'history';
|
|
5
|
+
import type { Route, SpaRouterConfig } from '../../types/router';
|
|
6
|
+
export default class PageHandler {
|
|
7
7
|
history: History;
|
|
8
8
|
config: SpaRouterConfig;
|
|
9
9
|
protected readonly defaultAnimation: RouterAnimate;
|
|
@@ -13,10 +13,11 @@ declare class PageHandler {
|
|
|
13
13
|
protected lastUnloadPage: PageInstance | null;
|
|
14
14
|
protected navigationBarHandler: NavigationBarHandler;
|
|
15
15
|
homePage: string;
|
|
16
|
+
originHomePage: string;
|
|
16
17
|
constructor(config: SpaRouterConfig, history: History);
|
|
17
18
|
get currentPage(): string;
|
|
18
19
|
get appId(): string;
|
|
19
|
-
get router(): import("
|
|
20
|
+
get router(): import("../../types/router").Router;
|
|
20
21
|
get routerMode(): "hash" | "browser" | "multi";
|
|
21
22
|
get customRoutes(): Record<string, string | string[]>;
|
|
22
23
|
get routes(): Route[];
|
|
@@ -27,6 +28,7 @@ declare class PageHandler {
|
|
|
27
28
|
get animationDuration(): number;
|
|
28
29
|
set pathname(p: string);
|
|
29
30
|
get pathname(): string;
|
|
31
|
+
get originPathname(): string;
|
|
30
32
|
get basename(): string;
|
|
31
33
|
get pageConfig(): Route | undefined;
|
|
32
34
|
isTabBar(pathname: string): boolean;
|
|
@@ -42,11 +44,10 @@ declare class PageHandler {
|
|
|
42
44
|
load(page: PageInstance, pageConfig: Route | undefined, stampId: string, pageNo?: number): void;
|
|
43
45
|
unload(page?: PageInstance | null, delta?: number, top?: boolean): void;
|
|
44
46
|
show(page?: PageInstance | null, pageConfig?: Route, pageNo?: number): void;
|
|
45
|
-
hide(page?: PageInstance | null): void;
|
|
47
|
+
hide(page?: PageInstance | null, animation?: boolean): void;
|
|
46
48
|
addAnimation(pageEl?: HTMLElement | null, first?: boolean): void;
|
|
47
49
|
getPageContainer(page?: PageInstance | null): HTMLElement | null;
|
|
48
|
-
getScrollingElement(page?: PageInstance | null):
|
|
50
|
+
getScrollingElement(page?: PageInstance | null): (Window & typeof globalThis) | HTMLElement;
|
|
49
51
|
bindPageEvents(page: PageInstance, config?: Partial<PageConfig>): void;
|
|
50
52
|
triggerRouterChange(): void;
|
|
51
53
|
}
|
|
52
|
-
export { PageHandler as default };
|
package/dist/router/page.js
CHANGED
|
@@ -15,6 +15,7 @@ class PageHandler {
|
|
|
15
15
|
this.defaultAnimation = { duration: 300, delay: 50 };
|
|
16
16
|
this.config = config;
|
|
17
17
|
this.homePage = getHomePage(this.routes[0].path, this.basename, this.customRoutes, this.config.entryPagePath);
|
|
18
|
+
this.originHomePage = this.config.entryPagePath || this.routes[0].path || this.basename;
|
|
18
19
|
this.mount();
|
|
19
20
|
this.navigationBarHandler = new NavigationBarHandler(this);
|
|
20
21
|
}
|
|
@@ -48,14 +49,14 @@ class PageHandler {
|
|
|
48
49
|
}
|
|
49
50
|
set pathname(p) { this.router.pathname = p; }
|
|
50
51
|
get pathname() { return this.router.pathname; }
|
|
52
|
+
// Note: 把 pathname 转换为原始路径,主要是处理 customRoutes 和 basename
|
|
53
|
+
get originPathname() { return routesAlias.getOrigin(addLeadingSlash(stripBasename(this.pathname, this.basename))); }
|
|
51
54
|
get basename() { return this.router.basename || ''; }
|
|
52
55
|
get pageConfig() {
|
|
53
|
-
const routePath = addLeadingSlash(stripBasename(this.pathname, this.basename));
|
|
54
56
|
const homePage = addLeadingSlash(this.homePage);
|
|
55
57
|
return this.routes.find(r => {
|
|
56
|
-
var _a;
|
|
57
58
|
const pagePath = addLeadingSlash(r.path);
|
|
58
|
-
return [pagePath, homePage].includes(
|
|
59
|
+
return [pagePath, homePage].includes(this.originPathname);
|
|
59
60
|
});
|
|
60
61
|
}
|
|
61
62
|
isTabBar(pathname) {
|
|
@@ -245,24 +246,35 @@ class PageHandler {
|
|
|
245
246
|
});
|
|
246
247
|
}
|
|
247
248
|
}
|
|
248
|
-
hide(page) {
|
|
249
|
-
var _a;
|
|
249
|
+
hide(page, animation = false) {
|
|
250
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
250
251
|
if (!page)
|
|
251
252
|
return;
|
|
252
253
|
// NOTE: 修复多页并发问题,此处可能因为路由跳转过快,执行时页面可能还没有创建成功
|
|
253
254
|
const pageEl = this.getPageContainer(page);
|
|
254
255
|
if (pageEl) {
|
|
255
|
-
if (
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
256
|
+
if (animation) {
|
|
257
|
+
if (this.hideTimer) {
|
|
258
|
+
clearTimeout(this.hideTimer);
|
|
259
|
+
this.hideTimer = null;
|
|
260
|
+
(_c = (_b = (_a = this.lastHidePage) === null || _a === void 0 ? void 0 : _a.classList) === null || _b === void 0 ? void 0 : _b.add) === null || _c === void 0 ? void 0 : _c.call(_b, 'taro_page_shade');
|
|
261
|
+
}
|
|
262
|
+
this.lastHidePage = pageEl;
|
|
263
|
+
this.hideTimer = setTimeout(() => {
|
|
264
|
+
this.hideTimer = null;
|
|
265
|
+
pageEl.classList.add('taro_page_shade');
|
|
266
|
+
}, this.animationDuration + this.animationDelay);
|
|
267
|
+
(_d = page.onHide) === null || _d === void 0 ? void 0 : _d.call(page);
|
|
259
268
|
}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
269
|
+
else {
|
|
270
|
+
if (this.hideTimer) {
|
|
271
|
+
clearTimeout(this.hideTimer);
|
|
272
|
+
this.hideTimer = null;
|
|
273
|
+
(_g = (_f = (_e = this.lastHidePage) === null || _e === void 0 ? void 0 : _e.classList) === null || _f === void 0 ? void 0 : _f.add) === null || _g === void 0 ? void 0 : _g.call(_f, 'taro_page_shade');
|
|
274
|
+
}
|
|
263
275
|
pageEl.classList.add('taro_page_shade');
|
|
264
|
-
|
|
265
|
-
|
|
276
|
+
this.lastHidePage = pageEl;
|
|
277
|
+
}
|
|
266
278
|
}
|
|
267
279
|
else {
|
|
268
280
|
setTimeout(() => this.hide(page), 0);
|