@tarojs/router 3.7.0-alpha.2 → 3.7.0-alpha.3
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/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 +200 -71
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.d.ts +0 -1
- package/dist/index.esm.js +202 -73
- package/dist/index.esm.js.map +1 -1
- 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 +49 -13
- package/dist/router/spa.d.ts +1 -1
- package/dist/router/spa.js +20 -16
- package/dist/style.d.ts +8 -0
- package/dist/style.js +71 -0
- package/package.json +9 -8
- package/dist/animation.d.ts +0 -4
- package/dist/animation.js +0 -29
package/dist/index.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createBrowserHistory, createHashHistory, Action, parsePath } from 'history';
|
|
2
|
-
import { Current,
|
|
2
|
+
import { Current, eventCenter, incrementId, createPageConfig, hooks, stringify, requestAnimationFrame as requestAnimationFrame$1 } from '@tarojs/runtime';
|
|
3
3
|
import MobileDetect from 'mobile-detect';
|
|
4
4
|
import queryString from 'query-string';
|
|
5
5
|
import { defineCustomElementTaroTabbar } from '@tarojs/components/dist/components';
|
|
@@ -147,7 +147,7 @@ class MpaHistory {
|
|
|
147
147
|
return url;
|
|
148
148
|
}
|
|
149
149
|
push(to, _state = {}) {
|
|
150
|
-
window.location.
|
|
150
|
+
window.location.assign(this.parseUrl(to));
|
|
151
151
|
// this.pushState(_state, '', this.parseUrl(to))
|
|
152
152
|
}
|
|
153
153
|
replace(to, _state = {}) {
|
|
@@ -430,11 +430,11 @@ function bindPageResize(page) {
|
|
|
430
430
|
|
|
431
431
|
const pageScrollFn = {};
|
|
432
432
|
let pageDOM = window;
|
|
433
|
-
function bindPageScroll(page,
|
|
433
|
+
function bindPageScroll(page, scrollEl, distance = 50) {
|
|
434
434
|
var _a;
|
|
435
435
|
const pagePath = (page ? page === null || page === void 0 ? void 0 : page.path : (_a = Current.router) === null || _a === void 0 ? void 0 : _a.path);
|
|
436
|
-
pageScrollFn[pagePath] &&
|
|
437
|
-
pageDOM =
|
|
436
|
+
pageScrollFn[pagePath] && scrollEl.removeEventListener('scroll', pageScrollFn[pagePath]);
|
|
437
|
+
pageDOM = scrollEl;
|
|
438
438
|
let isReachBottom = false;
|
|
439
439
|
pageScrollFn[pagePath] = function () {
|
|
440
440
|
var _a;
|
|
@@ -462,6 +462,78 @@ function getOffset() {
|
|
|
462
462
|
}
|
|
463
463
|
}
|
|
464
464
|
|
|
465
|
+
/**
|
|
466
|
+
* 插入页面动画需要的样式
|
|
467
|
+
*/
|
|
468
|
+
function loadAnimateStyle(ms = 300) {
|
|
469
|
+
const css = `
|
|
470
|
+
.taro_router .taro_page {
|
|
471
|
+
position: absolute;
|
|
472
|
+
left: 0;
|
|
473
|
+
top: 0;
|
|
474
|
+
width: 100%;
|
|
475
|
+
height: 100%;
|
|
476
|
+
background-color: #fff;
|
|
477
|
+
transform: translate(100%, 0);
|
|
478
|
+
transition: transform ${ms}ms;
|
|
479
|
+
z-index: 0;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
.taro_router .taro_page.taro_tabbar_page,
|
|
483
|
+
.taro_router .taro_page.taro_page_show.taro_page_stationed {
|
|
484
|
+
transform: none;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
.taro_router .taro_page.taro_page_show {
|
|
488
|
+
transform: translate(0, 0);
|
|
489
|
+
}`;
|
|
490
|
+
addStyle(css);
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* 插入路由相关样式
|
|
494
|
+
*/
|
|
495
|
+
function loadRouterStyle(usingWindowScroll) {
|
|
496
|
+
const css = `
|
|
497
|
+
.taro_router {
|
|
498
|
+
overflow: hidden;
|
|
499
|
+
position: relative;
|
|
500
|
+
width: 100%;
|
|
501
|
+
height: 100%;
|
|
502
|
+
min-height: 100vh;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
.taro-tabbar__container .taro_router {
|
|
506
|
+
min-height: calc(100vh - 50px);
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
.taro_page {
|
|
510
|
+
width: 100%;
|
|
511
|
+
height: 100%;
|
|
512
|
+
${usingWindowScroll ? '' : `
|
|
513
|
+
overflow-x: hidden;
|
|
514
|
+
overflow-y: scroll;
|
|
515
|
+
max-height: 100vh;
|
|
516
|
+
`}
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
.taro-tabbar__container .taro-tabbar__panel {
|
|
520
|
+
overflow: hidden;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
.taro-tabbar__container .taro_page.taro_tabbar_page {
|
|
524
|
+
max-height: calc(100vh - 50px);
|
|
525
|
+
}
|
|
526
|
+
`;
|
|
527
|
+
addStyle(css);
|
|
528
|
+
}
|
|
529
|
+
function addStyle(css) {
|
|
530
|
+
if (!css)
|
|
531
|
+
return;
|
|
532
|
+
const style = document.createElement('style');
|
|
533
|
+
style.innerHTML = css;
|
|
534
|
+
document.getElementsByTagName('head')[0].appendChild(style);
|
|
535
|
+
}
|
|
536
|
+
|
|
465
537
|
// @ts-nocheck
|
|
466
538
|
function initTabbar(config) {
|
|
467
539
|
if (config.tabBar == null) {
|
|
@@ -522,6 +594,17 @@ class MultiPageHandler {
|
|
|
522
594
|
return !!pagePath && this.tabBarList.some(t => t.pagePath === pagePath);
|
|
523
595
|
}
|
|
524
596
|
get search() { return location.search.substr(1); }
|
|
597
|
+
get usingWindowScroll() {
|
|
598
|
+
var _a;
|
|
599
|
+
let usingWindowScroll = true;
|
|
600
|
+
if (typeof ((_a = this.pageConfig) === null || _a === void 0 ? void 0 : _a.usingWindowScroll) === 'boolean') {
|
|
601
|
+
usingWindowScroll = this.pageConfig.usingWindowScroll;
|
|
602
|
+
}
|
|
603
|
+
const win = window;
|
|
604
|
+
win.__taroAppConfig || (win.__taroAppConfig = {});
|
|
605
|
+
win.__taroAppConfig.usingWindowScroll = usingWindowScroll;
|
|
606
|
+
return usingWindowScroll;
|
|
607
|
+
}
|
|
525
608
|
getQuery(search = '', options = {}) {
|
|
526
609
|
search = search ? `${search}&${this.search}` : this.search;
|
|
527
610
|
const query = search
|
|
@@ -531,6 +614,7 @@ class MultiPageHandler {
|
|
|
531
614
|
}
|
|
532
615
|
mount() {
|
|
533
616
|
setHistoryMode(this.routerMode, this.router.basename);
|
|
617
|
+
loadRouterStyle(this.usingWindowScroll);
|
|
534
618
|
const appId = this.appId;
|
|
535
619
|
let app = document.getElementById(appId);
|
|
536
620
|
let isPosition = true;
|
|
@@ -567,7 +651,20 @@ class MultiPageHandler {
|
|
|
567
651
|
const pageEl = this.getPageContainer(page);
|
|
568
652
|
if (pageEl && !(pageEl === null || pageEl === void 0 ? void 0 : pageEl['__isReady'])) {
|
|
569
653
|
const el = pageEl.firstElementChild;
|
|
570
|
-
|
|
654
|
+
const componentOnReady = el === null || el === void 0 ? void 0 : el['componentOnReady'];
|
|
655
|
+
if (componentOnReady) {
|
|
656
|
+
componentOnReady === null || componentOnReady === void 0 ? void 0 : componentOnReady().then(() => {
|
|
657
|
+
requestAnimationFrame(() => {
|
|
658
|
+
var _a;
|
|
659
|
+
(_a = page.onReady) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
660
|
+
pageEl['__isReady'] = true;
|
|
661
|
+
});
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
else {
|
|
665
|
+
(_a = page.onReady) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
666
|
+
pageEl['__isReady'] = true;
|
|
667
|
+
}
|
|
571
668
|
onLoad && (pageEl['__page'] = page);
|
|
572
669
|
}
|
|
573
670
|
}
|
|
@@ -577,11 +674,14 @@ class MultiPageHandler {
|
|
|
577
674
|
return;
|
|
578
675
|
(_a = page.onLoad) === null || _a === void 0 ? void 0 : _a.call(page, this.getQuery('', page.options), () => {
|
|
579
676
|
var _a;
|
|
580
|
-
|
|
581
|
-
|
|
677
|
+
if (this.isTabBar) {
|
|
678
|
+
const pageEl = this.getPageContainer(page);
|
|
679
|
+
pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.add('taro_tabbar_page');
|
|
680
|
+
}
|
|
582
681
|
this.onReady(page, true);
|
|
583
682
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
584
|
-
this.bindPageEvents(page,
|
|
683
|
+
this.bindPageEvents(page, pageConfig);
|
|
684
|
+
this.triggerRouterChange();
|
|
585
685
|
});
|
|
586
686
|
}
|
|
587
687
|
getPageContainer(page) {
|
|
@@ -595,17 +695,33 @@ class MultiPageHandler {
|
|
|
595
695
|
? document.querySelector(`.taro_page#${id}`)
|
|
596
696
|
: document.querySelector('.taro_page') ||
|
|
597
697
|
document.querySelector('.taro_router'));
|
|
598
|
-
return el
|
|
698
|
+
return el;
|
|
699
|
+
}
|
|
700
|
+
getScrollingElement(page) {
|
|
701
|
+
if (this.usingWindowScroll)
|
|
702
|
+
return window;
|
|
703
|
+
return this.getPageContainer(page) || window;
|
|
599
704
|
}
|
|
600
|
-
bindPageEvents(page,
|
|
705
|
+
bindPageEvents(page, config = {}) {
|
|
601
706
|
var _a;
|
|
602
|
-
|
|
603
|
-
pageEl = this.getPageContainer();
|
|
604
|
-
}
|
|
707
|
+
const scrollEl = this.getScrollingElement(page);
|
|
605
708
|
const distance = config.onReachBottomDistance || ((_a = this.config.window) === null || _a === void 0 ? void 0 : _a.onReachBottomDistance) || 50;
|
|
606
|
-
bindPageScroll(page,
|
|
709
|
+
bindPageScroll(page, scrollEl, distance);
|
|
607
710
|
bindPageResize(page);
|
|
608
711
|
}
|
|
712
|
+
triggerRouterChange() {
|
|
713
|
+
/**
|
|
714
|
+
* @tarojs/runtime 中生命周期跑在 promise 中,所以这里需要 setTimeout 延迟事件调用
|
|
715
|
+
* TODO 考虑将生命周期返回 Promise,用于处理相关事件调用顺序
|
|
716
|
+
*/
|
|
717
|
+
setTimeout(() => {
|
|
718
|
+
eventCenter.trigger('__afterTaroRouterChange', {
|
|
719
|
+
toLocation: {
|
|
720
|
+
path: this.pathname
|
|
721
|
+
}
|
|
722
|
+
});
|
|
723
|
+
}, 0);
|
|
724
|
+
}
|
|
609
725
|
}
|
|
610
726
|
|
|
611
727
|
const createStampId$1 = incrementId();
|
|
@@ -621,6 +737,9 @@ const launchStampId$1 = createStampId$1();
|
|
|
621
737
|
function createMultiRouter(app, config, framework) {
|
|
622
738
|
var _a, _b, _c, _d, _e, _f;
|
|
623
739
|
return __awaiter(this, void 0, void 0, function* () {
|
|
740
|
+
if (typeof app.onUnhandledRejection === 'function') {
|
|
741
|
+
window.addEventListener('unhandledrejection', app.onUnhandledRejection);
|
|
742
|
+
}
|
|
624
743
|
RouterConfig.config = config;
|
|
625
744
|
const handler = new MultiPageHandler(config);
|
|
626
745
|
const launchParam = {
|
|
@@ -663,42 +782,12 @@ function createMultiRouter(app, config, framework) {
|
|
|
663
782
|
const loadConfig = Object.assign({}, pageConfig);
|
|
664
783
|
delete loadConfig['path'];
|
|
665
784
|
delete loadConfig['load'];
|
|
666
|
-
const page = createPageConfig(enablePullDownRefresh ? hooks.call('createPullDownComponent', el,
|
|
785
|
+
const page = createPageConfig(enablePullDownRefresh ? hooks.call('createPullDownComponent', el, pathName, framework, handler.PullDownRefresh) : el, pathName + stringify(launchParam), {}, loadConfig);
|
|
667
786
|
handler.load(page, pageConfig);
|
|
668
787
|
(_f = app.onShow) === null || _f === void 0 ? void 0 : _f.call(app, launchParam);
|
|
669
788
|
});
|
|
670
789
|
}
|
|
671
790
|
|
|
672
|
-
/**
|
|
673
|
-
* 插入页面动画需要的样式
|
|
674
|
-
*/
|
|
675
|
-
function loadAnimateStyle(ms = 300) {
|
|
676
|
-
const css = `
|
|
677
|
-
.taro_router .taro_page {
|
|
678
|
-
position: absolute;
|
|
679
|
-
left: 0;
|
|
680
|
-
top: 0;
|
|
681
|
-
width: 100%;
|
|
682
|
-
height: 100%;
|
|
683
|
-
background-color: #fff;
|
|
684
|
-
transform: translate(100%, 0);
|
|
685
|
-
transition: transform ${ms}ms;
|
|
686
|
-
z-index: 0;
|
|
687
|
-
}
|
|
688
|
-
|
|
689
|
-
.taro_router .taro_page.taro_tabbar_page,
|
|
690
|
-
.taro_router .taro_page.taro_page_show.taro_page_stationed {
|
|
691
|
-
transform: none;
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
.taro_router .taro_page.taro_page_show {
|
|
695
|
-
transform: translate(0, 0);
|
|
696
|
-
}`;
|
|
697
|
-
const style = document.createElement('style');
|
|
698
|
-
style.innerHTML = css;
|
|
699
|
-
document.getElementsByTagName('head')[0].appendChild(style);
|
|
700
|
-
}
|
|
701
|
-
|
|
702
791
|
/* eslint-disable dot-notation */
|
|
703
792
|
function setDisplay(el, type = '') {
|
|
704
793
|
if (el) {
|
|
@@ -784,6 +873,17 @@ class PageHandler {
|
|
|
784
873
|
}
|
|
785
874
|
return search.substring(1);
|
|
786
875
|
}
|
|
876
|
+
get usingWindowScroll() {
|
|
877
|
+
var _a;
|
|
878
|
+
let usingWindowScroll = false;
|
|
879
|
+
if (typeof ((_a = this.pageConfig) === null || _a === void 0 ? void 0 : _a.usingWindowScroll) === 'boolean') {
|
|
880
|
+
usingWindowScroll = this.pageConfig.usingWindowScroll;
|
|
881
|
+
}
|
|
882
|
+
const win = window;
|
|
883
|
+
win.__taroAppConfig || (win.__taroAppConfig = {});
|
|
884
|
+
win.__taroAppConfig.usingWindowScroll = usingWindowScroll;
|
|
885
|
+
return usingWindowScroll;
|
|
886
|
+
}
|
|
787
887
|
getQuery(stamp = '', search = '', options = {}) {
|
|
788
888
|
search = search ? `${search}&${this.search}` : this.search;
|
|
789
889
|
const query = search
|
|
@@ -794,7 +894,9 @@ class PageHandler {
|
|
|
794
894
|
}
|
|
795
895
|
mount() {
|
|
796
896
|
setHistoryMode(this.routerMode, this.router.basename);
|
|
897
|
+
this.pathname = history.location.pathname;
|
|
797
898
|
this.animation && loadAnimateStyle(this.animationDuration);
|
|
899
|
+
loadRouterStyle(this.usingWindowScroll);
|
|
798
900
|
const appId = this.appId;
|
|
799
901
|
let app = document.getElementById(appId);
|
|
800
902
|
let isPosition = true;
|
|
@@ -834,7 +936,7 @@ class PageHandler {
|
|
|
834
936
|
const componentOnReady = el === null || el === void 0 ? void 0 : el['componentOnReady'];
|
|
835
937
|
if (componentOnReady) {
|
|
836
938
|
componentOnReady === null || componentOnReady === void 0 ? void 0 : componentOnReady().then(() => {
|
|
837
|
-
requestAnimationFrame(() => {
|
|
939
|
+
requestAnimationFrame$1(() => {
|
|
838
940
|
var _a;
|
|
839
941
|
(_a = page.onReady) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
840
942
|
pageEl['__isReady'] = true;
|
|
@@ -861,7 +963,8 @@ class PageHandler {
|
|
|
861
963
|
this.isTabBar(this.pathname) && pageEl.classList.add('taro_tabbar_page');
|
|
862
964
|
this.addAnimation(pageEl, pageNo === 0);
|
|
863
965
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
864
|
-
this.bindPageEvents(page,
|
|
966
|
+
this.bindPageEvents(page, pageConfig);
|
|
967
|
+
this.triggerRouterChange();
|
|
865
968
|
}
|
|
866
969
|
else {
|
|
867
970
|
(_b = page.onLoad) === null || _b === void 0 ? void 0 : _b.call(page, param, () => {
|
|
@@ -871,7 +974,8 @@ class PageHandler {
|
|
|
871
974
|
this.addAnimation(pageEl, pageNo === 0);
|
|
872
975
|
this.onReady(page, true);
|
|
873
976
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
874
|
-
this.bindPageEvents(page,
|
|
977
|
+
this.bindPageEvents(page, pageConfig);
|
|
978
|
+
this.triggerRouterChange();
|
|
875
979
|
});
|
|
876
980
|
}
|
|
877
981
|
}
|
|
@@ -891,6 +995,9 @@ class PageHandler {
|
|
|
891
995
|
const pageEl = this.getPageContainer(page);
|
|
892
996
|
pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.remove('taro_page_stationed');
|
|
893
997
|
pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.remove('taro_page_show');
|
|
998
|
+
if (pageEl) {
|
|
999
|
+
pageEl.style.zIndex = '1';
|
|
1000
|
+
}
|
|
894
1001
|
this.unloadTimer = setTimeout(() => {
|
|
895
1002
|
var _a, _b;
|
|
896
1003
|
this.unloadTimer = null;
|
|
@@ -916,7 +1023,8 @@ class PageHandler {
|
|
|
916
1023
|
setDisplay(pageEl);
|
|
917
1024
|
this.addAnimation(pageEl, pageNo === 0);
|
|
918
1025
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
919
|
-
this.bindPageEvents(page,
|
|
1026
|
+
this.bindPageEvents(page, pageConfig);
|
|
1027
|
+
this.triggerRouterChange();
|
|
920
1028
|
}
|
|
921
1029
|
else {
|
|
922
1030
|
(_b = page.onLoad) === null || _b === void 0 ? void 0 : _b.call(page, param, () => {
|
|
@@ -925,7 +1033,8 @@ class PageHandler {
|
|
|
925
1033
|
this.addAnimation(pageEl, pageNo === 0);
|
|
926
1034
|
this.onReady(page, false);
|
|
927
1035
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
928
|
-
this.bindPageEvents(page,
|
|
1036
|
+
this.bindPageEvents(page, pageConfig);
|
|
1037
|
+
this.triggerRouterChange();
|
|
929
1038
|
});
|
|
930
1039
|
}
|
|
931
1040
|
}
|
|
@@ -979,23 +1088,42 @@ class PageHandler {
|
|
|
979
1088
|
? document.querySelector(`.taro_page#${id}`)
|
|
980
1089
|
: document.querySelector('.taro_page') ||
|
|
981
1090
|
document.querySelector('.taro_router'));
|
|
982
|
-
return el
|
|
1091
|
+
return el;
|
|
983
1092
|
}
|
|
984
|
-
|
|
1093
|
+
getScrollingElement(page) {
|
|
1094
|
+
if (this.usingWindowScroll)
|
|
1095
|
+
return window;
|
|
1096
|
+
return this.getPageContainer(page) || window;
|
|
1097
|
+
}
|
|
1098
|
+
bindPageEvents(page, config = {}) {
|
|
985
1099
|
var _a;
|
|
986
|
-
|
|
987
|
-
pageEl = this.getPageContainer();
|
|
988
|
-
}
|
|
1100
|
+
const scrollEl = this.getScrollingElement(page);
|
|
989
1101
|
const distance = config.onReachBottomDistance || ((_a = this.config.window) === null || _a === void 0 ? void 0 : _a.onReachBottomDistance) || 50;
|
|
990
|
-
bindPageScroll(page,
|
|
1102
|
+
bindPageScroll(page, scrollEl, distance);
|
|
991
1103
|
bindPageResize(page);
|
|
992
1104
|
}
|
|
1105
|
+
triggerRouterChange() {
|
|
1106
|
+
/**
|
|
1107
|
+
* @tarojs/runtime 中生命周期跑在 promise 中,所以这里需要 setTimeout 延迟事件调用
|
|
1108
|
+
* TODO 考虑将生命周期返回 Promise,用于处理相关事件调用顺序
|
|
1109
|
+
*/
|
|
1110
|
+
setTimeout(() => {
|
|
1111
|
+
eventCenter.trigger('__afterTaroRouterChange', {
|
|
1112
|
+
toLocation: {
|
|
1113
|
+
path: this.pathname
|
|
1114
|
+
}
|
|
1115
|
+
});
|
|
1116
|
+
}, 0);
|
|
1117
|
+
}
|
|
993
1118
|
}
|
|
994
1119
|
|
|
995
1120
|
const createStampId = incrementId();
|
|
996
1121
|
let launchStampId = createStampId();
|
|
997
1122
|
function createRouter(app, config, framework) {
|
|
998
1123
|
var _a, _b;
|
|
1124
|
+
if (typeof app.onUnhandledRejection === 'function') {
|
|
1125
|
+
window.addEventListener('unhandledrejection', app.onUnhandledRejection);
|
|
1126
|
+
}
|
|
999
1127
|
RouterConfig.config = config;
|
|
1000
1128
|
const handler = new PageHandler(config);
|
|
1001
1129
|
routesAlias.set(handler.router.customRoutes);
|
|
@@ -1020,8 +1148,10 @@ function createRouter(app, config, framework) {
|
|
|
1020
1148
|
(_a = app.onLaunch) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
|
|
1021
1149
|
app.onError && window.addEventListener('error', e => { var _a; return (_a = app.onError) === null || _a === void 0 ? void 0 : _a.call(app, e.message); });
|
|
1022
1150
|
const render = ({ location, action }) => __awaiter(this, void 0, void 0, function* () {
|
|
1023
|
-
var _c, _d, _e, _f, _g;
|
|
1151
|
+
var _c, _d, _e, _f, _g, _h;
|
|
1024
1152
|
handler.pathname = decodeURI(location.pathname);
|
|
1153
|
+
if ((_c = window.__taroAppConfig) === null || _c === void 0 ? void 0 : _c.usingWindowScroll)
|
|
1154
|
+
window.scrollTo(0, 0);
|
|
1025
1155
|
eventCenter.trigger('__taroRouterChange', {
|
|
1026
1156
|
toLocation: {
|
|
1027
1157
|
path: handler.pathname
|
|
@@ -1034,9 +1164,13 @@ function createRouter(app, config, framework) {
|
|
|
1034
1164
|
}
|
|
1035
1165
|
catch (error) {
|
|
1036
1166
|
if (error.status === 404) {
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1167
|
+
const notFoundEvent = {
|
|
1168
|
+
isEntryPage: stacks.length === 0,
|
|
1169
|
+
path: handler.pathname,
|
|
1170
|
+
query: handler.getQuery(createStampId()),
|
|
1171
|
+
};
|
|
1172
|
+
(_d = app.onPageNotFound) === null || _d === void 0 ? void 0 : _d.call(app, notFoundEvent);
|
|
1173
|
+
eventCenter.trigger('__taroRouterNotFound', notFoundEvent);
|
|
1040
1174
|
}
|
|
1041
1175
|
else if (/Loading hot update .* failed./.test(error.message)) {
|
|
1042
1176
|
// NOTE: webpack5 与 prebundle 搭配使用时,开发环境下初次启动时偶发错误,由于 HMR 加载 chunk hash 错误,导致热更新失败
|
|
@@ -1049,16 +1183,16 @@ function createRouter(app, config, framework) {
|
|
|
1049
1183
|
if (!element)
|
|
1050
1184
|
return;
|
|
1051
1185
|
const pageConfig = handler.pageConfig;
|
|
1052
|
-
let enablePullDownRefresh = ((
|
|
1186
|
+
let enablePullDownRefresh = ((_e = config === null || config === void 0 ? void 0 : config.window) === null || _e === void 0 ? void 0 : _e.enablePullDownRefresh) || false;
|
|
1053
1187
|
if (pageConfig) {
|
|
1054
|
-
setTitle((
|
|
1188
|
+
setTitle((_f = pageConfig.navigationBarTitleText) !== null && _f !== void 0 ? _f : document.title);
|
|
1055
1189
|
if (typeof pageConfig.enablePullDownRefresh === 'boolean') {
|
|
1056
1190
|
enablePullDownRefresh = pageConfig.enablePullDownRefresh;
|
|
1057
1191
|
}
|
|
1058
1192
|
}
|
|
1059
1193
|
const currentPage = Current.page;
|
|
1060
1194
|
const pathname = handler.pathname;
|
|
1061
|
-
const methodName = (
|
|
1195
|
+
const methodName = (_g = stacks.method) !== null && _g !== void 0 ? _g : '';
|
|
1062
1196
|
const cacheTabs = stacks.getTabs();
|
|
1063
1197
|
let shouldLoad = false;
|
|
1064
1198
|
stacks.method = '';
|
|
@@ -1083,11 +1217,11 @@ function createRouter(app, config, framework) {
|
|
|
1083
1217
|
else if (stacks.length > 0) {
|
|
1084
1218
|
const firstIns = stacks.getItem(0);
|
|
1085
1219
|
if (handler.isTabBar(firstIns.path)) {
|
|
1086
|
-
handler.unload(currentPage, stacks.length - 1);
|
|
1220
|
+
handler.unload(currentPage, stacks.length - 1, true);
|
|
1087
1221
|
stacks.pushTab(firstIns.path.split('?')[0]);
|
|
1088
1222
|
}
|
|
1089
1223
|
else {
|
|
1090
|
-
handler.unload(currentPage, stacks.length);
|
|
1224
|
+
handler.unload(currentPage, stacks.length, true);
|
|
1091
1225
|
}
|
|
1092
1226
|
}
|
|
1093
1227
|
if (cacheTabs[handler.pathname]) {
|
|
@@ -1122,7 +1256,7 @@ function createRouter(app, config, framework) {
|
|
|
1122
1256
|
shouldLoad = true;
|
|
1123
1257
|
}
|
|
1124
1258
|
if (shouldLoad || stacks.length < 1) {
|
|
1125
|
-
const el = (
|
|
1259
|
+
const el = (_h = element.default) !== null && _h !== void 0 ? _h : element;
|
|
1126
1260
|
const loadConfig = Object.assign({}, pageConfig);
|
|
1127
1261
|
const stacksIndex = stacks.length;
|
|
1128
1262
|
delete loadConfig['path'];
|
|
@@ -1135,16 +1269,11 @@ function createRouter(app, config, framework) {
|
|
|
1135
1269
|
else {
|
|
1136
1270
|
pageStampId = createStampId();
|
|
1137
1271
|
}
|
|
1138
|
-
const page = createPageConfig(enablePullDownRefresh ? hooks.call('createPullDownComponent', el,
|
|
1272
|
+
const page = createPageConfig(enablePullDownRefresh ? hooks.call('createPullDownComponent', el, pathname, framework, handler.PullDownRefresh, pageStampId) : el, pathname + stringify(handler.getQuery(pageStampId)), {}, loadConfig);
|
|
1139
1273
|
if (params)
|
|
1140
1274
|
page.options = params;
|
|
1141
1275
|
handler.load(page, pageConfig, pageStampId, stacksIndex);
|
|
1142
1276
|
}
|
|
1143
|
-
eventCenter.trigger('__afterTaroRouterChange', {
|
|
1144
|
-
toLocation: {
|
|
1145
|
-
path: handler.pathname
|
|
1146
|
-
}
|
|
1147
|
-
});
|
|
1148
1277
|
});
|
|
1149
1278
|
const routePath = addLeadingSlash(stripBasename(history.location.pathname, handler.basename));
|
|
1150
1279
|
if (routePath === '/') {
|