@tarojs/router 3.3.17 → 3.3.18
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 +339 -206
- package/dist/index.js.map +1 -1
- package/dist/router.esm.js +357 -242
- package/dist/router.esm.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -58,8 +58,18 @@ function prependBasename(url) {
|
|
|
58
58
|
|
|
59
59
|
return basename.replace(/\/$/, '') + '/' + url.replace(/^\//, '');
|
|
60
60
|
}
|
|
61
|
-
var hasBasename = function (path, prefix) {
|
|
62
|
-
|
|
61
|
+
var hasBasename = function (path, prefix) {
|
|
62
|
+
if ( path === void 0 ) path = '';
|
|
63
|
+
if ( prefix === void 0 ) prefix = '';
|
|
64
|
+
|
|
65
|
+
return new RegExp('^' + prefix + '(\\/|\\?|#|$)', 'i').test(path);
|
|
66
|
+
};
|
|
67
|
+
var stripBasename = function (path, prefix) {
|
|
68
|
+
if ( path === void 0 ) path = '';
|
|
69
|
+
if ( prefix === void 0 ) prefix = '';
|
|
70
|
+
|
|
71
|
+
return hasBasename(path, prefix) ? path.substr(prefix.length) : path;
|
|
72
|
+
};
|
|
63
73
|
|
|
64
74
|
var Stacks = function Stacks() {
|
|
65
75
|
this.stacks = [];
|
|
@@ -87,9 +97,11 @@ Stacks.prototype.get = function get () {
|
|
|
87
97
|
Stacks.prototype.getItem = function getItem (index) {
|
|
88
98
|
return this.stacks[index];
|
|
89
99
|
};
|
|
90
|
-
Stacks.prototype.getLastIndex = function getLastIndex (pathname) {
|
|
100
|
+
Stacks.prototype.getLastIndex = function getLastIndex (pathname, stateWith) {
|
|
101
|
+
if ( stateWith === void 0 ) stateWith = 1;
|
|
102
|
+
|
|
91
103
|
var list = [].concat( this.stacks ).reverse();
|
|
92
|
-
return list.findIndex(function (page, i) { var _a; return i
|
|
104
|
+
return list.findIndex(function (page, i) { var _a; return i >= stateWith && ((_a = page.path) === null || _a === void 0 ? void 0 : _a.replace(/\?.*/g, '')) === pathname; });
|
|
93
105
|
};
|
|
94
106
|
Stacks.prototype.getDelta = function getDelta (pathname) {
|
|
95
107
|
if (this.backDelta >= 1) {
|
|
@@ -98,8 +110,10 @@ Stacks.prototype.getDelta = function getDelta (pathname) {
|
|
|
98
110
|
// NOTE: 此处为了修复浏览器后退多级页面,在大量重复路由状况下可能出现判断错误的情况 (增强判断能力只能考虑在 query 中新增参数来判断,暂时搁置)
|
|
99
111
|
return this.getLastIndex(pathname) || 1;
|
|
100
112
|
};
|
|
101
|
-
Stacks.prototype.getPrevIndex = function getPrevIndex (pathname) {
|
|
102
|
-
|
|
113
|
+
Stacks.prototype.getPrevIndex = function getPrevIndex (pathname, stateWith) {
|
|
114
|
+
if ( stateWith === void 0 ) stateWith = 1;
|
|
115
|
+
|
|
116
|
+
var lastIndex = this.getLastIndex(pathname, stateWith);
|
|
103
117
|
if (lastIndex < 0) {
|
|
104
118
|
return -1;
|
|
105
119
|
}
|
|
@@ -125,21 +139,29 @@ var RoutesAlias = function RoutesAlias() {
|
|
|
125
139
|
var this$1 = this;
|
|
126
140
|
|
|
127
141
|
this.conf = [];
|
|
128
|
-
this.getConfig = function (url) {
|
|
142
|
+
this.getConfig = function (url) {
|
|
143
|
+
if ( url === void 0 ) url = '';
|
|
144
|
+
|
|
129
145
|
var customRoute = this$1.conf.filter(function (arr) {
|
|
130
146
|
return arr.includes(url);
|
|
131
147
|
});
|
|
132
148
|
return customRoute[0];
|
|
133
149
|
};
|
|
134
|
-
this.getOrigin = function (url) {
|
|
150
|
+
this.getOrigin = function (url) {
|
|
151
|
+
if ( url === void 0 ) url = '';
|
|
152
|
+
|
|
135
153
|
var _a;
|
|
136
154
|
return ((_a = this$1.getConfig(url)) === null || _a === void 0 ? void 0 : _a[0]) || url;
|
|
137
155
|
};
|
|
138
|
-
this.getAlias = function (url) {
|
|
156
|
+
this.getAlias = function (url) {
|
|
157
|
+
if ( url === void 0 ) url = '';
|
|
158
|
+
|
|
139
159
|
var _a;
|
|
140
160
|
return ((_a = this$1.getConfig(url)) === null || _a === void 0 ? void 0 : _a[1]) || url;
|
|
141
161
|
};
|
|
142
|
-
this.getAll = function (url) {
|
|
162
|
+
this.getAll = function (url) {
|
|
163
|
+
if ( url === void 0 ) url = '';
|
|
164
|
+
|
|
143
165
|
return this$1.conf.filter(function (arr) {
|
|
144
166
|
return arr.includes(url);
|
|
145
167
|
}).reduce(function (p, a) {
|
|
@@ -166,27 +188,7 @@ RoutesAlias.prototype.set = function set (customRoutes) {
|
|
|
166
188
|
|
|
167
189
|
for (var key in customRoutes) loop( key );
|
|
168
190
|
};
|
|
169
|
-
var routesAlias = new RoutesAlias();
|
|
170
|
-
var isTabBar = function (config) {
|
|
171
|
-
var _a, _b;
|
|
172
|
-
var ref = config.router;
|
|
173
|
-
var customRoutes = ref.customRoutes; if ( customRoutes === void 0 ) customRoutes = {};
|
|
174
|
-
var basename = ref.basename; if ( basename === void 0 ) basename = '';
|
|
175
|
-
var pathname = ref.pathname;
|
|
176
|
-
var routePath = stripBasename(pathname, basename);
|
|
177
|
-
var pagePath = ((_a = Object.entries(customRoutes).find(function (ref) {
|
|
178
|
-
var target = ref[1];
|
|
179
|
-
|
|
180
|
-
if (typeof target === 'string') {
|
|
181
|
-
return target === routePath;
|
|
182
|
-
}
|
|
183
|
-
else if ((target === null || target === void 0 ? void 0 : target.length) > 0) {
|
|
184
|
-
return target.includes(routePath);
|
|
185
|
-
}
|
|
186
|
-
return false;
|
|
187
|
-
})) === null || _a === void 0 ? void 0 : _a[0]) || routePath;
|
|
188
|
-
return !!pagePath && (((_b = config.tabBar) === null || _b === void 0 ? void 0 : _b.list) || []).some(function (t) { return t.pagePath === pagePath; });
|
|
189
|
-
};
|
|
191
|
+
var routesAlias = new RoutesAlias();
|
|
190
192
|
|
|
191
193
|
function processNavigateUrl(option) {
|
|
192
194
|
var _a;
|
|
@@ -920,108 +922,6 @@ var UniversalRouter = function () {
|
|
|
920
922
|
|
|
921
923
|
UniversalRouter.pathToRegexp = pathToRegexp_1;
|
|
922
924
|
|
|
923
|
-
// @ts-nocheck
|
|
924
|
-
function initTabbar(config) {
|
|
925
|
-
if (config.tabBar == null) {
|
|
926
|
-
return;
|
|
927
|
-
}
|
|
928
|
-
// TODO: 找到 tabbar 的类型
|
|
929
|
-
var tabbar = document.createElement('taro-tabbar');
|
|
930
|
-
var homePage = config.entryPagePath || (config.pages ? config.pages[0] : '');
|
|
931
|
-
tabbar.conf = config.tabBar;
|
|
932
|
-
tabbar.conf.homePage = exports.history.location.pathname === '/' ? homePage : exports.history.location.pathname;
|
|
933
|
-
var routerConfig = config.router;
|
|
934
|
-
tabbar.conf.mode = routerConfig && routerConfig.mode ? routerConfig.mode : 'hash';
|
|
935
|
-
if (routerConfig.customRoutes) {
|
|
936
|
-
tabbar.conf.custom = true;
|
|
937
|
-
tabbar.conf.customRoutes = routerConfig.customRoutes;
|
|
938
|
-
}
|
|
939
|
-
else {
|
|
940
|
-
tabbar.conf.custom = false;
|
|
941
|
-
tabbar.conf.customRoutes = {};
|
|
942
|
-
}
|
|
943
|
-
if (typeof routerConfig.basename !== 'undefined') {
|
|
944
|
-
tabbar.conf.basename = routerConfig.basename;
|
|
945
|
-
}
|
|
946
|
-
var container = document.getElementById('container');
|
|
947
|
-
// eslint-disable-next-line no-unused-expressions
|
|
948
|
-
container === null || container === void 0 ? void 0 : container.appendChild(tabbar);
|
|
949
|
-
taro.initTabBarApis(config);
|
|
950
|
-
}
|
|
951
|
-
|
|
952
|
-
var routerConfig = Object.create(null);
|
|
953
|
-
function init(config) {
|
|
954
|
-
var _a;
|
|
955
|
-
config.router.mode = config.router.mode || 'hash';
|
|
956
|
-
setHistoryMode(config.router.mode, config.router.basename);
|
|
957
|
-
Object.assign(routerConfig, config);
|
|
958
|
-
(_a = document.getElementById('app')) === null || _a === void 0 ? void 0 : _a.remove();
|
|
959
|
-
var container = document.createElement('div');
|
|
960
|
-
container.classList.add('taro-tabbar__container');
|
|
961
|
-
container.id = 'container';
|
|
962
|
-
var panel = document.createElement('div');
|
|
963
|
-
panel.classList.add('taro-tabbar__panel');
|
|
964
|
-
var app = document.createElement('div');
|
|
965
|
-
app.id = 'app';
|
|
966
|
-
app.classList.add('taro_router');
|
|
967
|
-
panel.appendChild(app);
|
|
968
|
-
container.appendChild(panel);
|
|
969
|
-
document.body.appendChild(container);
|
|
970
|
-
initTabbar(config);
|
|
971
|
-
}
|
|
972
|
-
|
|
973
|
-
var pageScrollFn;
|
|
974
|
-
var pageDOM = window;
|
|
975
|
-
function bindPageScroll(page, config) {
|
|
976
|
-
pageDOM.removeEventListener('scroll', pageScrollFn);
|
|
977
|
-
pageDOM = getScrollContainer();
|
|
978
|
-
var distance = config.onReachBottomDistance || 50;
|
|
979
|
-
var isReachBottom = false;
|
|
980
|
-
pageScrollFn = function () {
|
|
981
|
-
page.onPageScroll && page.onPageScroll({
|
|
982
|
-
scrollTop: pageDOM instanceof Window ? window.scrollY : pageDOM.scrollTop
|
|
983
|
-
});
|
|
984
|
-
if (isReachBottom && getOffset() > distance) {
|
|
985
|
-
isReachBottom = false;
|
|
986
|
-
}
|
|
987
|
-
if (page.onReachBottom &&
|
|
988
|
-
!isReachBottom &&
|
|
989
|
-
getOffset() < distance) {
|
|
990
|
-
isReachBottom = true;
|
|
991
|
-
page.onReachBottom();
|
|
992
|
-
}
|
|
993
|
-
};
|
|
994
|
-
pageDOM.addEventListener('scroll', pageScrollFn, false);
|
|
995
|
-
}
|
|
996
|
-
window.addEventListener('DOMSubtreeModified', function (e) {
|
|
997
|
-
var _a;
|
|
998
|
-
// @ts-ignore
|
|
999
|
-
var className = (_a = e.target) === null || _a === void 0 ? void 0 : _a.className;
|
|
1000
|
-
if (className && /taro-tabbar__/.test(className)) {
|
|
1001
|
-
pageDOM.removeEventListener('scroll', pageScrollFn);
|
|
1002
|
-
pageDOM = getScrollContainer();
|
|
1003
|
-
pageDOM.addEventListener('scroll', pageScrollFn, false);
|
|
1004
|
-
}
|
|
1005
|
-
}, false);
|
|
1006
|
-
function getScrollContainer() {
|
|
1007
|
-
if (document.querySelector('.taro-tabbar__tabbar') === null) {
|
|
1008
|
-
// 没设置tabbar
|
|
1009
|
-
return window;
|
|
1010
|
-
}
|
|
1011
|
-
else {
|
|
1012
|
-
// 有设置tabbar
|
|
1013
|
-
return document.querySelector('.taro-tabbar__panel') || window;
|
|
1014
|
-
}
|
|
1015
|
-
}
|
|
1016
|
-
function getOffset() {
|
|
1017
|
-
if (pageDOM instanceof Window) {
|
|
1018
|
-
return document.documentElement.scrollHeight - window.scrollY - window.innerHeight;
|
|
1019
|
-
}
|
|
1020
|
-
else {
|
|
1021
|
-
return pageDOM.scrollHeight - pageDOM.scrollTop - pageDOM.clientHeight;
|
|
1022
|
-
}
|
|
1023
|
-
}
|
|
1024
|
-
|
|
1025
925
|
function createCommonjsModule(fn, module) {
|
|
1026
926
|
return module = { exports: {} }, fn(module, module.exports), module.exports;
|
|
1027
927
|
}
|
|
@@ -1578,9 +1478,171 @@ var queryString_5 = queryString.stringifyUrl;
|
|
|
1578
1478
|
var queryString_6 = queryString.pick;
|
|
1579
1479
|
var queryString_7 = queryString.exclude;
|
|
1580
1480
|
|
|
1581
|
-
|
|
1481
|
+
var pageScrollFn;
|
|
1482
|
+
var pageDOM = window;
|
|
1483
|
+
function bindPageScroll(page, config) {
|
|
1484
|
+
pageDOM.removeEventListener('scroll', pageScrollFn);
|
|
1485
|
+
pageDOM = getScrollContainer();
|
|
1486
|
+
var distance = config.onReachBottomDistance || 50;
|
|
1487
|
+
var isReachBottom = false;
|
|
1488
|
+
pageScrollFn = function () {
|
|
1489
|
+
page.onPageScroll && page.onPageScroll({
|
|
1490
|
+
scrollTop: pageDOM instanceof Window ? window.scrollY : pageDOM.scrollTop
|
|
1491
|
+
});
|
|
1492
|
+
if (isReachBottom && getOffset() > distance) {
|
|
1493
|
+
isReachBottom = false;
|
|
1494
|
+
}
|
|
1495
|
+
if (page.onReachBottom &&
|
|
1496
|
+
!isReachBottom &&
|
|
1497
|
+
getOffset() < distance) {
|
|
1498
|
+
isReachBottom = true;
|
|
1499
|
+
page.onReachBottom();
|
|
1500
|
+
}
|
|
1501
|
+
};
|
|
1502
|
+
pageDOM.addEventListener('scroll', pageScrollFn, false);
|
|
1503
|
+
}
|
|
1504
|
+
window.addEventListener('DOMSubtreeModified', function (e) {
|
|
1505
|
+
var target = e.target;
|
|
1506
|
+
var className = target === null || target === void 0 ? void 0 : target.className;
|
|
1507
|
+
if (className && /taro_page/.test(className)) {
|
|
1508
|
+
pageDOM.removeEventListener('scroll', pageScrollFn);
|
|
1509
|
+
pageDOM = getScrollContainer();
|
|
1510
|
+
pageDOM.addEventListener('scroll', pageScrollFn, false);
|
|
1511
|
+
}
|
|
1512
|
+
}, false);
|
|
1513
|
+
function getScrollContainer() {
|
|
1514
|
+
var _a;
|
|
1515
|
+
var id = (_a = runtime.Current.page) === null || _a === void 0 ? void 0 : _a.path;
|
|
1516
|
+
var el = (id
|
|
1517
|
+
? document.getElementById(id)
|
|
1518
|
+
: document.querySelector('.taro_page') ||
|
|
1519
|
+
document.querySelector('.taro_router'));
|
|
1520
|
+
return el || window;
|
|
1521
|
+
}
|
|
1522
|
+
function getOffset() {
|
|
1523
|
+
if (pageDOM instanceof Window) {
|
|
1524
|
+
return document.documentElement.scrollHeight - window.scrollY - window.innerHeight;
|
|
1525
|
+
}
|
|
1526
|
+
else {
|
|
1527
|
+
return pageDOM.scrollHeight - pageDOM.scrollTop - pageDOM.clientHeight;
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1530
|
+
|
|
1531
|
+
/**
|
|
1532
|
+
* 插入页面动画需要的样式
|
|
1533
|
+
*/
|
|
1534
|
+
function loadAnimateStyle(ms) {
|
|
1535
|
+
if ( ms === void 0 ) ms = 300;
|
|
1536
|
+
|
|
1537
|
+
var css = "\n.taro_router .taro_page {\n position: absolute;\n left: 0;\n top: 0;\n width: 100%;\n height: 100%;\n transform: translate3d(100%, 0, 0);\n transition: transform " + ms + "ms;\n}\n\n.taro_router .taro_page.taro_tabbar_page {\n transform: none;\n}\n\n.taro_router .taro_page.taro_page_show {\n transform: translate3d(0, 0, 0);\n}";
|
|
1538
|
+
var style = document.createElement('style');
|
|
1539
|
+
style.innerHTML = css;
|
|
1540
|
+
document.getElementsByTagName('head')[0].appendChild(style);
|
|
1541
|
+
}
|
|
1542
|
+
|
|
1543
|
+
// @ts-nocheck
|
|
1544
|
+
function initTabbar(config) {
|
|
1545
|
+
if (config.tabBar == null) {
|
|
1546
|
+
return;
|
|
1547
|
+
}
|
|
1548
|
+
// TODO: custom-tab-bar
|
|
1549
|
+
var tabbar = document.createElement('taro-tabbar');
|
|
1550
|
+
var homePage = config.entryPagePath || (config.pages ? config.pages[0] : '');
|
|
1551
|
+
tabbar.conf = config.tabBar;
|
|
1552
|
+
tabbar.conf.homePage = exports.history.location.pathname === '/' ? homePage : exports.history.location.pathname;
|
|
1553
|
+
var routerConfig = config.router;
|
|
1554
|
+
tabbar.conf.mode = routerConfig && routerConfig.mode ? routerConfig.mode : 'hash';
|
|
1555
|
+
if (routerConfig.customRoutes) {
|
|
1556
|
+
tabbar.conf.custom = true;
|
|
1557
|
+
tabbar.conf.customRoutes = routerConfig.customRoutes;
|
|
1558
|
+
}
|
|
1559
|
+
else {
|
|
1560
|
+
tabbar.conf.custom = false;
|
|
1561
|
+
tabbar.conf.customRoutes = {};
|
|
1562
|
+
}
|
|
1563
|
+
if (typeof routerConfig.basename !== 'undefined') {
|
|
1564
|
+
tabbar.conf.basename = routerConfig.basename;
|
|
1565
|
+
}
|
|
1566
|
+
var container = document.getElementById('container');
|
|
1567
|
+
container === null || container === void 0 ? void 0 : container.appendChild(tabbar);
|
|
1568
|
+
taro.initTabBarApis(config);
|
|
1569
|
+
}
|
|
1570
|
+
|
|
1571
|
+
function setDisplay(el, type) {
|
|
1572
|
+
if ( type === void 0 ) type = '';
|
|
1573
|
+
|
|
1574
|
+
if (el) {
|
|
1575
|
+
el.style.display = type;
|
|
1576
|
+
}
|
|
1577
|
+
}
|
|
1578
|
+
var PageHandler = function PageHandler(config) {
|
|
1579
|
+
this.defaultAnimation = { duration: 300, delay: 50 };
|
|
1580
|
+
this.config = config;
|
|
1581
|
+
this.mount();
|
|
1582
|
+
};
|
|
1583
|
+
|
|
1584
|
+
var prototypeAccessors$1 = { appId: { configurable: true },router: { configurable: true },routerMode: { configurable: true },customRoutes: { configurable: true },routes: { configurable: true },tabBarList: { configurable: true },PullDownRefresh: { configurable: true },animation: { configurable: true },animationDelay: { configurable: true },animationDuration: { configurable: true },pathname: { configurable: true },basename: { configurable: true },pageConfig: { configurable: true },isTabBar: { configurable: true },search: { configurable: true } };
|
|
1585
|
+
prototypeAccessors$1.appId.get = function () { return 'app'; };
|
|
1586
|
+
prototypeAccessors$1.router.get = function () { return this.config.router; };
|
|
1587
|
+
prototypeAccessors$1.routerMode.get = function () { return this.router.mode || 'hash'; };
|
|
1588
|
+
prototypeAccessors$1.customRoutes.get = function () { return this.router.customRoutes || {}; };
|
|
1589
|
+
prototypeAccessors$1.routes.get = function () { return this.config.routes; };
|
|
1590
|
+
prototypeAccessors$1.tabBarList.get = function () { var _a; return ((_a = this.config.tabBar) === null || _a === void 0 ? void 0 : _a.list) || []; };
|
|
1591
|
+
prototypeAccessors$1.PullDownRefresh.get = function () { return this.config.PullDownRefresh; };
|
|
1592
|
+
prototypeAccessors$1.animation.get = function () { var _a, _b; return (_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.animation) !== null && _b !== void 0 ? _b : this.defaultAnimation; };
|
|
1593
|
+
prototypeAccessors$1.animationDelay.get = function () {
|
|
1594
|
+
var _a;
|
|
1595
|
+
return typeof this.animation === 'object'
|
|
1596
|
+
? this.animation.delay
|
|
1597
|
+
: this.animation
|
|
1598
|
+
? (_a = this.defaultAnimation) === null || _a === void 0 ? void 0 : _a.delay
|
|
1599
|
+
: 0;
|
|
1600
|
+
};
|
|
1601
|
+
prototypeAccessors$1.animationDuration.get = function () {
|
|
1602
|
+
var _a;
|
|
1603
|
+
return typeof this.animation === 'object'
|
|
1604
|
+
? this.animation.duration
|
|
1605
|
+
: this.animation
|
|
1606
|
+
? (_a = this.defaultAnimation) === null || _a === void 0 ? void 0 : _a.duration
|
|
1607
|
+
: 0;
|
|
1608
|
+
};
|
|
1609
|
+
prototypeAccessors$1.pathname.set = function (p) { this.router.pathname = p; };
|
|
1610
|
+
prototypeAccessors$1.pathname.get = function () { return this.router.pathname; };
|
|
1611
|
+
prototypeAccessors$1.basename.get = function () { return this.router.basename || ''; };
|
|
1612
|
+
prototypeAccessors$1.pageConfig.get = function () {
|
|
1613
|
+
var this$1 = this;
|
|
1614
|
+
|
|
1615
|
+
return this.routes.find(function (r) {
|
|
1616
|
+
var _a;
|
|
1617
|
+
var routePath = stripBasename(this$1.pathname, this$1.basename);
|
|
1618
|
+
var pagePath = addLeadingSlash(r.path);
|
|
1619
|
+
return pagePath === routePath || ((_a = routesAlias.getConfig(pagePath)) === null || _a === void 0 ? void 0 : _a.includes(routePath));
|
|
1620
|
+
});
|
|
1621
|
+
};
|
|
1622
|
+
prototypeAccessors$1.isTabBar.get = function () {
|
|
1623
|
+
var _a;
|
|
1624
|
+
var routePath = stripBasename(this.pathname, this.basename);
|
|
1625
|
+
var pagePath = ((_a = Object.entries(this.customRoutes).find(function (ref) {
|
|
1626
|
+
var target = ref[1];
|
|
1627
|
+
|
|
1628
|
+
if (typeof target === 'string') {
|
|
1629
|
+
return target === routePath;
|
|
1630
|
+
}
|
|
1631
|
+
else if ((target === null || target === void 0 ? void 0 : target.length) > 0) {
|
|
1632
|
+
return target.includes(routePath);
|
|
1633
|
+
}
|
|
1634
|
+
return false;
|
|
1635
|
+
})) === null || _a === void 0 ? void 0 : _a[0]) || routePath;
|
|
1636
|
+
return !!pagePath && this.tabBarList.some(function (t) { return t.pagePath === pagePath; });
|
|
1637
|
+
};
|
|
1638
|
+
PageHandler.prototype.isSamePage = function isSamePage (page) {
|
|
1639
|
+
var routePath = stripBasename(this.pathname, this.basename);
|
|
1640
|
+
var pagePath = stripBasename(page === null || page === void 0 ? void 0 : page.path, this.basename);
|
|
1641
|
+
return pagePath.startsWith(routePath + '?');
|
|
1642
|
+
};
|
|
1643
|
+
prototypeAccessors$1.search.get = function () {
|
|
1582
1644
|
var search = '?';
|
|
1583
|
-
if (
|
|
1645
|
+
if (this.routerMode) {
|
|
1584
1646
|
var idx = location.hash.indexOf('?');
|
|
1585
1647
|
if (idx > -1) {
|
|
1586
1648
|
search = location.hash.slice(idx);
|
|
@@ -1590,11 +1652,11 @@ function getSearch() {
|
|
|
1590
1652
|
search = location.search;
|
|
1591
1653
|
}
|
|
1592
1654
|
return search.substr(1);
|
|
1593
|
-
}
|
|
1594
|
-
|
|
1595
|
-
|
|
1655
|
+
};
|
|
1656
|
+
PageHandler.prototype.getQuery = function getQuery (stamp) {
|
|
1657
|
+
if ( stamp === void 0 ) stamp = 0;
|
|
1596
1658
|
|
|
1597
|
-
var search =
|
|
1659
|
+
var search = this.search;
|
|
1598
1660
|
var query = search
|
|
1599
1661
|
? queryString.parse(search)
|
|
1600
1662
|
: {};
|
|
@@ -1602,11 +1664,32 @@ var qs = function (stamp) {
|
|
|
1602
1664
|
query.stamp = stamp.toString();
|
|
1603
1665
|
}
|
|
1604
1666
|
return query;
|
|
1605
|
-
};
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1667
|
+
};
|
|
1668
|
+
PageHandler.prototype.mount = function mount () {
|
|
1669
|
+
var _a;
|
|
1670
|
+
setHistoryMode(this.routerMode, this.router.basename);
|
|
1671
|
+
(_a = document.getElementById('app')) === null || _a === void 0 ? void 0 : _a.remove();
|
|
1672
|
+
this.animation && loadAnimateStyle(this.animationDuration);
|
|
1673
|
+
var app = document.createElement('div');
|
|
1674
|
+
app.id = this.appId;
|
|
1675
|
+
app.classList.add('taro_router');
|
|
1676
|
+
if (this.tabBarList.length > 1) {
|
|
1677
|
+
var container = document.createElement('div');
|
|
1678
|
+
container.classList.add('taro-tabbar__container');
|
|
1679
|
+
container.id = 'container';
|
|
1680
|
+
var panel = document.createElement('div');
|
|
1681
|
+
panel.classList.add('taro-tabbar__panel');
|
|
1682
|
+
panel.appendChild(app);
|
|
1683
|
+
container.appendChild(panel);
|
|
1684
|
+
document.body.appendChild(container);
|
|
1685
|
+
initTabbar(this.config);
|
|
1686
|
+
}
|
|
1687
|
+
else {
|
|
1688
|
+
document.body.appendChild(app);
|
|
1689
|
+
}
|
|
1690
|
+
};
|
|
1691
|
+
PageHandler.prototype.onReady = function onReady (page, onLoad) {
|
|
1692
|
+
if ( onLoad === void 0 ) onLoad = true;
|
|
1610
1693
|
|
|
1611
1694
|
var _a, _b;
|
|
1612
1695
|
var pageEl = document.getElementById(page.path);
|
|
@@ -1620,81 +1703,135 @@ function pageOnReady(page, onLoad) {
|
|
|
1620
1703
|
});
|
|
1621
1704
|
onLoad && (pageEl['__page'] = page);
|
|
1622
1705
|
}
|
|
1623
|
-
}
|
|
1624
|
-
function
|
|
1625
|
-
|
|
1626
|
-
|
|
1706
|
+
};
|
|
1707
|
+
PageHandler.prototype.load = function load (page, pageConfig, stacksIndex) {
|
|
1708
|
+
var this$1 = this;
|
|
1709
|
+
if ( pageConfig === void 0 ) pageConfig = {};
|
|
1710
|
+
if ( stacksIndex === void 0 ) stacksIndex = 0;
|
|
1627
1711
|
|
|
1628
1712
|
if (!page)
|
|
1629
1713
|
{ return; }
|
|
1630
1714
|
var pageEl = document.getElementById(page.path);
|
|
1631
1715
|
if (pageEl) {
|
|
1632
|
-
pageEl
|
|
1716
|
+
setDisplay(pageEl);
|
|
1717
|
+
this.isTabBar && pageEl.classList.add('taro_tabbar_page');
|
|
1718
|
+
this.addAnimation(pageEl, stacksIndex === 0);
|
|
1633
1719
|
}
|
|
1634
1720
|
else {
|
|
1635
|
-
page.onLoad(
|
|
1721
|
+
page.onLoad(this.getQuery(stacksIndex), function () {
|
|
1722
|
+
pageEl = document.getElementById(page.path);
|
|
1723
|
+
this$1.isTabBar && (pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.add('taro_tabbar_page'));
|
|
1724
|
+
this$1.addAnimation(pageEl, stacksIndex === 0);
|
|
1725
|
+
this$1.onReady(page, true);
|
|
1726
|
+
});
|
|
1636
1727
|
}
|
|
1637
1728
|
stacks.push(page);
|
|
1638
1729
|
page.onShow();
|
|
1639
1730
|
bindPageScroll(page, pageConfig);
|
|
1640
|
-
}
|
|
1641
|
-
function
|
|
1642
|
-
|
|
1731
|
+
};
|
|
1732
|
+
PageHandler.prototype.unload = function unload (page, delta, top) {
|
|
1733
|
+
var this$1 = this;
|
|
1734
|
+
if ( delta === void 0 ) delta = 1;
|
|
1735
|
+
if ( top === void 0 ) top = false;
|
|
1643
1736
|
|
|
1737
|
+
var _a;
|
|
1644
1738
|
if (!page)
|
|
1645
1739
|
{ return; }
|
|
1646
1740
|
stacks.delta = --delta;
|
|
1647
1741
|
stacks.pop();
|
|
1648
|
-
|
|
1742
|
+
if (this.animation && top) {
|
|
1743
|
+
if (this.unloadTimer) {
|
|
1744
|
+
clearTimeout(this.unloadTimer);
|
|
1745
|
+
(_a = this.lastUnloadPage) === null || _a === void 0 ? void 0 : _a.onUnload();
|
|
1746
|
+
this.unloadTimer = null;
|
|
1747
|
+
}
|
|
1748
|
+
this.lastUnloadPage = page;
|
|
1749
|
+
var pageEl = document.getElementById(page.path);
|
|
1750
|
+
pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.remove('taro_page_show');
|
|
1751
|
+
this.unloadTimer = setTimeout(function () {
|
|
1752
|
+
var _a;
|
|
1753
|
+
this$1.unloadTimer = null;
|
|
1754
|
+
(_a = this$1.lastUnloadPage) === null || _a === void 0 ? void 0 : _a.onUnload();
|
|
1755
|
+
}, this.animationDuration);
|
|
1756
|
+
}
|
|
1649
1757
|
if (delta >= 1)
|
|
1650
|
-
{
|
|
1651
|
-
}
|
|
1652
|
-
function
|
|
1653
|
-
|
|
1654
|
-
|
|
1758
|
+
{ this.unload(stacks.last, delta); }
|
|
1759
|
+
};
|
|
1760
|
+
PageHandler.prototype.show = function show (page, pageConfig, stacksIndex) {
|
|
1761
|
+
var this$1 = this;
|
|
1762
|
+
if ( pageConfig === void 0 ) pageConfig = {};
|
|
1763
|
+
if ( stacksIndex === void 0 ) stacksIndex = 0;
|
|
1655
1764
|
|
|
1656
1765
|
if (!page)
|
|
1657
1766
|
{ return; }
|
|
1658
1767
|
page.onShow();
|
|
1659
1768
|
var pageEl = document.getElementById(page.path);
|
|
1660
1769
|
if (pageEl) {
|
|
1661
|
-
pageEl
|
|
1770
|
+
setDisplay(pageEl);
|
|
1771
|
+
this.addAnimation(pageEl, stacksIndex === 0);
|
|
1662
1772
|
}
|
|
1663
1773
|
else {
|
|
1664
|
-
page.onLoad(
|
|
1774
|
+
page.onLoad(this.getQuery(stacksIndex), function () {
|
|
1775
|
+
pageEl = document.getElementById(page.path);
|
|
1776
|
+
this$1.addAnimation(pageEl, stacksIndex === 0);
|
|
1777
|
+
this$1.onReady(page, false);
|
|
1778
|
+
});
|
|
1665
1779
|
}
|
|
1666
1780
|
bindPageScroll(page, pageConfig);
|
|
1667
|
-
}
|
|
1668
|
-
function
|
|
1781
|
+
};
|
|
1782
|
+
PageHandler.prototype.hide = function hide (page) {
|
|
1783
|
+
var this$1 = this;
|
|
1784
|
+
|
|
1669
1785
|
if (!page)
|
|
1670
1786
|
{ return; }
|
|
1671
1787
|
// NOTE: 修复多页并发问题,此处可能因为路由跳转过快,执行时页面可能还没有创建成功
|
|
1672
1788
|
var pageEl = document.getElementById(page.path);
|
|
1673
1789
|
if (pageEl) {
|
|
1674
|
-
|
|
1790
|
+
if (this.hideTimer) {
|
|
1791
|
+
clearTimeout(this.hideTimer);
|
|
1792
|
+
this.hideTimer = null;
|
|
1793
|
+
setDisplay(this.lastHidePage, 'none');
|
|
1794
|
+
}
|
|
1795
|
+
this.lastHidePage = pageEl;
|
|
1796
|
+
this.hideTimer = setTimeout(function () {
|
|
1797
|
+
this$1.hideTimer = null;
|
|
1798
|
+
setDisplay(this$1.lastHidePage, 'none');
|
|
1799
|
+
}, this.animationDelay);
|
|
1675
1800
|
page.onHide();
|
|
1676
1801
|
}
|
|
1677
1802
|
else {
|
|
1678
|
-
setTimeout(function () { return
|
|
1803
|
+
setTimeout(function () { return this$1.hide(page); }, 0);
|
|
1679
1804
|
}
|
|
1680
|
-
}
|
|
1805
|
+
};
|
|
1806
|
+
PageHandler.prototype.addAnimation = function addAnimation (pageEl, first) {
|
|
1807
|
+
if ( first === void 0 ) first = false;
|
|
1808
|
+
|
|
1809
|
+
if (!pageEl)
|
|
1810
|
+
{ return; }
|
|
1811
|
+
if (this.animation && !first) {
|
|
1812
|
+
setTimeout(function () {
|
|
1813
|
+
pageEl.classList.add('taro_page_show');
|
|
1814
|
+
}, this.animationDelay);
|
|
1815
|
+
}
|
|
1816
|
+
else {
|
|
1817
|
+
pageEl.classList.add('taro_page_show');
|
|
1818
|
+
}
|
|
1819
|
+
};
|
|
1820
|
+
|
|
1821
|
+
Object.defineProperties( PageHandler.prototype, prototypeAccessors$1 );
|
|
1681
1822
|
|
|
1682
1823
|
/* eslint-disable dot-notation */
|
|
1683
1824
|
function createRouter(app, config, framework) {
|
|
1684
1825
|
var _a;
|
|
1685
|
-
|
|
1686
|
-
var routes = [];
|
|
1826
|
+
var handler = new PageHandler(config);
|
|
1687
1827
|
var runtimeHooks = runtime.container.get(runtime.SERVICE_IDENTIFIER.Hooks);
|
|
1688
|
-
routesAlias.set(
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
});
|
|
1696
|
-
}
|
|
1697
|
-
var basename = config.router.basename;
|
|
1828
|
+
routesAlias.set(handler.router.customRoutes);
|
|
1829
|
+
var basename = handler.router.basename;
|
|
1830
|
+
var routes = handler.routes.map(function (route) { return ({
|
|
1831
|
+
path: routesAlias.getAll(addLeadingSlash(route.path)),
|
|
1832
|
+
action: route.load
|
|
1833
|
+
}); });
|
|
1834
|
+
var entryPagePath = config.entryPagePath || ((_a = routes[0].path) === null || _a === void 0 ? void 0 : _a[0]);
|
|
1698
1835
|
var router = new UniversalRouter(routes, { baseUrl: basename || '' });
|
|
1699
1836
|
app.onLaunch();
|
|
1700
1837
|
var render = async function (ref) {
|
|
@@ -1702,15 +1839,15 @@ function createRouter(app, config, framework) {
|
|
|
1702
1839
|
var action = ref.action;
|
|
1703
1840
|
|
|
1704
1841
|
var _a, _b, _c, _d;
|
|
1705
|
-
|
|
1842
|
+
handler.pathname = location.pathname;
|
|
1706
1843
|
var element;
|
|
1707
1844
|
try {
|
|
1708
|
-
element = await router.resolve(
|
|
1845
|
+
element = await router.resolve(handler.router.forcePath || handler.pathname);
|
|
1709
1846
|
}
|
|
1710
1847
|
catch (error) {
|
|
1711
1848
|
if (error.status === 404) {
|
|
1712
1849
|
(_a = app.onPageNotFound) === null || _a === void 0 ? void 0 : _a.call(app, {
|
|
1713
|
-
path:
|
|
1850
|
+
path: handler.pathname
|
|
1714
1851
|
});
|
|
1715
1852
|
}
|
|
1716
1853
|
else {
|
|
@@ -1719,16 +1856,11 @@ function createRouter(app, config, framework) {
|
|
|
1719
1856
|
}
|
|
1720
1857
|
if (!element)
|
|
1721
1858
|
{ return; }
|
|
1722
|
-
var pageConfig =
|
|
1723
|
-
var _a;
|
|
1724
|
-
var path = addLeadingSlash(r.path);
|
|
1725
|
-
var urlPath = stripBasename(location.pathname, routerConfig.router.basename);
|
|
1726
|
-
return path === urlPath || ((_a = routesAlias.getConfig(path)) === null || _a === void 0 ? void 0 : _a.includes(urlPath));
|
|
1727
|
-
});
|
|
1859
|
+
var pageConfig = handler.pageConfig;
|
|
1728
1860
|
var enablePullDownRefresh = false;
|
|
1729
1861
|
runtime.eventCenter.trigger('__taroRouterChange', {
|
|
1730
1862
|
toLocation: {
|
|
1731
|
-
path:
|
|
1863
|
+
path: handler.pathname
|
|
1732
1864
|
}
|
|
1733
1865
|
});
|
|
1734
1866
|
if (pageConfig) {
|
|
@@ -1736,37 +1868,38 @@ function createRouter(app, config, framework) {
|
|
|
1736
1868
|
enablePullDownRefresh = pageConfig.enablePullDownRefresh;
|
|
1737
1869
|
}
|
|
1738
1870
|
var currentPage = runtime.Current.page;
|
|
1739
|
-
var pathname =
|
|
1871
|
+
var pathname = handler.pathname;
|
|
1740
1872
|
var shouldLoad = false;
|
|
1741
1873
|
if (action === 'POP') {
|
|
1742
1874
|
// NOTE: 浏览器事件退后多次时,该事件只会被触发一次
|
|
1743
1875
|
var prevIndex = stacks.getPrevIndex(pathname);
|
|
1744
1876
|
var delta = stacks.getDelta(pathname);
|
|
1745
|
-
|
|
1877
|
+
handler.unload(currentPage, delta, prevIndex > -1);
|
|
1746
1878
|
if (prevIndex > -1) {
|
|
1747
|
-
|
|
1879
|
+
handler.show(stacks.getItem(prevIndex), pageConfig, prevIndex);
|
|
1748
1880
|
}
|
|
1749
1881
|
else {
|
|
1750
1882
|
shouldLoad = true;
|
|
1751
1883
|
}
|
|
1752
1884
|
}
|
|
1753
|
-
else
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
hidePage(currentPage);
|
|
1760
|
-
var prevIndex$1 = stacks.getPrevIndex(pathname);
|
|
1885
|
+
else {
|
|
1886
|
+
if (handler.isTabBar) {
|
|
1887
|
+
if (handler.isSamePage(currentPage))
|
|
1888
|
+
{ return; }
|
|
1889
|
+
var prevIndex$1 = stacks.getPrevIndex(pathname, 0);
|
|
1890
|
+
handler.hide(currentPage);
|
|
1761
1891
|
if (prevIndex$1 > -1) {
|
|
1762
1892
|
// NOTE: tabbar 页且之前出现过,直接复用
|
|
1763
|
-
return
|
|
1893
|
+
return handler.show(stacks.getItem(prevIndex$1), pageConfig, prevIndex$1);
|
|
1764
1894
|
}
|
|
1765
1895
|
}
|
|
1766
|
-
else {
|
|
1896
|
+
else if (action === 'REPLACE') {
|
|
1767
1897
|
var delta$1 = stacks.getDelta(pathname);
|
|
1768
1898
|
// NOTE: 页面路由记录并不会清空,只是移除掉缓存的 stack 以及页面
|
|
1769
|
-
|
|
1899
|
+
handler.unload(currentPage, delta$1);
|
|
1900
|
+
}
|
|
1901
|
+
else if (action === 'PUSH') {
|
|
1902
|
+
handler.hide(currentPage);
|
|
1770
1903
|
}
|
|
1771
1904
|
shouldLoad = true;
|
|
1772
1905
|
}
|
|
@@ -1776,15 +1909,15 @@ function createRouter(app, config, framework) {
|
|
|
1776
1909
|
var stacksIndex = stacks.length;
|
|
1777
1910
|
delete loadConfig['path'];
|
|
1778
1911
|
delete loadConfig['load'];
|
|
1779
|
-
var page = runtime.createPageConfig(enablePullDownRefresh ? (_d = runtimeHooks.createPullDownComponent) === null || _d === void 0 ? void 0 : _d.call(runtimeHooks, el, location.pathname, framework,
|
|
1780
|
-
return
|
|
1912
|
+
var page = runtime.createPageConfig(enablePullDownRefresh ? (_d = runtimeHooks.createPullDownComponent) === null || _d === void 0 ? void 0 : _d.call(runtimeHooks, el, location.pathname, framework, handler.PullDownRefresh) : el, pathname + runtime.stringify(handler.getQuery(stacksIndex)), {}, loadConfig);
|
|
1913
|
+
return handler.load(page, pageConfig, stacksIndex);
|
|
1781
1914
|
}
|
|
1782
1915
|
};
|
|
1783
1916
|
if (exports.history.location.pathname === '/') {
|
|
1784
|
-
exports.history.replace(prependBasename(
|
|
1917
|
+
exports.history.replace(prependBasename(entryPagePath + exports.history.location.search));
|
|
1785
1918
|
}
|
|
1786
1919
|
render({ location: exports.history.location, action: r.Push });
|
|
1787
|
-
app.onShow(
|
|
1920
|
+
app.onShow(handler.getQuery(stacks.length));
|
|
1788
1921
|
return exports.history.listen(render);
|
|
1789
1922
|
}
|
|
1790
1923
|
|