@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/events/scroll.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { PageInstance } from '@tarojs/runtime';
|
|
2
|
-
export declare function bindPageScroll(page: PageInstance,
|
|
2
|
+
export declare function bindPageScroll(page: PageInstance, scrollEl: HTMLElement | Window, distance?: number): void;
|
package/dist/events/scroll.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Current } from '@tarojs/runtime';
|
|
2
2
|
const pageScrollFn = {};
|
|
3
3
|
let pageDOM = window;
|
|
4
|
-
export function bindPageScroll(page,
|
|
4
|
+
export function bindPageScroll(page, scrollEl, distance = 50) {
|
|
5
5
|
var _a;
|
|
6
6
|
const pagePath = (page ? page === null || page === void 0 ? void 0 : page.path : (_a = Current.router) === null || _a === void 0 ? void 0 : _a.path);
|
|
7
|
-
pageScrollFn[pagePath] &&
|
|
8
|
-
pageDOM =
|
|
7
|
+
pageScrollFn[pagePath] && scrollEl.removeEventListener('scroll', pageScrollFn[pagePath]);
|
|
8
|
+
pageDOM = scrollEl;
|
|
9
9
|
let isReachBottom = false;
|
|
10
10
|
pageScrollFn[pagePath] = function () {
|
|
11
11
|
var _a;
|
package/dist/history.js
CHANGED
package/dist/index.cjs.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import Taro from "@tarojs/taro";
|
|
2
2
|
import { History } from "history";
|
|
3
|
-
/* eslint-disable dot-notation */
|
|
4
3
|
import { AppInstance } from "@tarojs/runtime";
|
|
5
4
|
import { MpaRouterConfig, SpaRouterConfig } from "../../types/router";
|
|
6
5
|
declare function navigateTo(option: Taro.navigateTo.Option): ReturnType<typeof Taro.navigateTo>;
|
package/dist/index.cjs.js
CHANGED
|
@@ -157,7 +157,7 @@ class MpaHistory {
|
|
|
157
157
|
return url;
|
|
158
158
|
}
|
|
159
159
|
push(to, _state = {}) {
|
|
160
|
-
window.location.
|
|
160
|
+
window.location.assign(this.parseUrl(to));
|
|
161
161
|
// this.pushState(_state, '', this.parseUrl(to))
|
|
162
162
|
}
|
|
163
163
|
replace(to, _state = {}) {
|
|
@@ -440,11 +440,11 @@ function bindPageResize(page) {
|
|
|
440
440
|
|
|
441
441
|
const pageScrollFn = {};
|
|
442
442
|
let pageDOM = window;
|
|
443
|
-
function bindPageScroll(page,
|
|
443
|
+
function bindPageScroll(page, scrollEl, distance = 50) {
|
|
444
444
|
var _a;
|
|
445
445
|
const pagePath = (page ? page === null || page === void 0 ? void 0 : page.path : (_a = runtime.Current.router) === null || _a === void 0 ? void 0 : _a.path);
|
|
446
|
-
pageScrollFn[pagePath] &&
|
|
447
|
-
pageDOM =
|
|
446
|
+
pageScrollFn[pagePath] && scrollEl.removeEventListener('scroll', pageScrollFn[pagePath]);
|
|
447
|
+
pageDOM = scrollEl;
|
|
448
448
|
let isReachBottom = false;
|
|
449
449
|
pageScrollFn[pagePath] = function () {
|
|
450
450
|
var _a;
|
|
@@ -472,6 +472,78 @@ function getOffset() {
|
|
|
472
472
|
}
|
|
473
473
|
}
|
|
474
474
|
|
|
475
|
+
/**
|
|
476
|
+
* 插入页面动画需要的样式
|
|
477
|
+
*/
|
|
478
|
+
function loadAnimateStyle(ms = 300) {
|
|
479
|
+
const css = `
|
|
480
|
+
.taro_router .taro_page {
|
|
481
|
+
position: absolute;
|
|
482
|
+
left: 0;
|
|
483
|
+
top: 0;
|
|
484
|
+
width: 100%;
|
|
485
|
+
height: 100%;
|
|
486
|
+
background-color: #fff;
|
|
487
|
+
transform: translate(100%, 0);
|
|
488
|
+
transition: transform ${ms}ms;
|
|
489
|
+
z-index: 0;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
.taro_router .taro_page.taro_tabbar_page,
|
|
493
|
+
.taro_router .taro_page.taro_page_show.taro_page_stationed {
|
|
494
|
+
transform: none;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
.taro_router .taro_page.taro_page_show {
|
|
498
|
+
transform: translate(0, 0);
|
|
499
|
+
}`;
|
|
500
|
+
addStyle(css);
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* 插入路由相关样式
|
|
504
|
+
*/
|
|
505
|
+
function loadRouterStyle(usingWindowScroll) {
|
|
506
|
+
const css = `
|
|
507
|
+
.taro_router {
|
|
508
|
+
overflow: hidden;
|
|
509
|
+
position: relative;
|
|
510
|
+
width: 100%;
|
|
511
|
+
height: 100%;
|
|
512
|
+
min-height: 100vh;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
.taro-tabbar__container .taro_router {
|
|
516
|
+
min-height: calc(100vh - 50px);
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
.taro_page {
|
|
520
|
+
width: 100%;
|
|
521
|
+
height: 100%;
|
|
522
|
+
${usingWindowScroll ? '' : `
|
|
523
|
+
overflow-x: hidden;
|
|
524
|
+
overflow-y: scroll;
|
|
525
|
+
max-height: 100vh;
|
|
526
|
+
`}
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
.taro-tabbar__container .taro-tabbar__panel {
|
|
530
|
+
overflow: hidden;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
.taro-tabbar__container .taro_page.taro_tabbar_page {
|
|
534
|
+
max-height: calc(100vh - 50px);
|
|
535
|
+
}
|
|
536
|
+
`;
|
|
537
|
+
addStyle(css);
|
|
538
|
+
}
|
|
539
|
+
function addStyle(css) {
|
|
540
|
+
if (!css)
|
|
541
|
+
return;
|
|
542
|
+
const style = document.createElement('style');
|
|
543
|
+
style.innerHTML = css;
|
|
544
|
+
document.getElementsByTagName('head')[0].appendChild(style);
|
|
545
|
+
}
|
|
546
|
+
|
|
475
547
|
// @ts-nocheck
|
|
476
548
|
function initTabbar(config) {
|
|
477
549
|
if (config.tabBar == null) {
|
|
@@ -532,6 +604,17 @@ class MultiPageHandler {
|
|
|
532
604
|
return !!pagePath && this.tabBarList.some(t => t.pagePath === pagePath);
|
|
533
605
|
}
|
|
534
606
|
get search() { return location.search.substr(1); }
|
|
607
|
+
get usingWindowScroll() {
|
|
608
|
+
var _a;
|
|
609
|
+
let usingWindowScroll = true;
|
|
610
|
+
if (typeof ((_a = this.pageConfig) === null || _a === void 0 ? void 0 : _a.usingWindowScroll) === 'boolean') {
|
|
611
|
+
usingWindowScroll = this.pageConfig.usingWindowScroll;
|
|
612
|
+
}
|
|
613
|
+
const win = window;
|
|
614
|
+
win.__taroAppConfig || (win.__taroAppConfig = {});
|
|
615
|
+
win.__taroAppConfig.usingWindowScroll = usingWindowScroll;
|
|
616
|
+
return usingWindowScroll;
|
|
617
|
+
}
|
|
535
618
|
getQuery(search = '', options = {}) {
|
|
536
619
|
search = search ? `${search}&${this.search}` : this.search;
|
|
537
620
|
const query = search
|
|
@@ -541,6 +624,7 @@ class MultiPageHandler {
|
|
|
541
624
|
}
|
|
542
625
|
mount() {
|
|
543
626
|
setHistoryMode(this.routerMode, this.router.basename);
|
|
627
|
+
loadRouterStyle(this.usingWindowScroll);
|
|
544
628
|
const appId = this.appId;
|
|
545
629
|
let app = document.getElementById(appId);
|
|
546
630
|
let isPosition = true;
|
|
@@ -577,7 +661,20 @@ class MultiPageHandler {
|
|
|
577
661
|
const pageEl = this.getPageContainer(page);
|
|
578
662
|
if (pageEl && !(pageEl === null || pageEl === void 0 ? void 0 : pageEl['__isReady'])) {
|
|
579
663
|
const el = pageEl.firstElementChild;
|
|
580
|
-
|
|
664
|
+
const componentOnReady = el === null || el === void 0 ? void 0 : el['componentOnReady'];
|
|
665
|
+
if (componentOnReady) {
|
|
666
|
+
componentOnReady === null || componentOnReady === void 0 ? void 0 : componentOnReady().then(() => {
|
|
667
|
+
requestAnimationFrame(() => {
|
|
668
|
+
var _a;
|
|
669
|
+
(_a = page.onReady) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
670
|
+
pageEl['__isReady'] = true;
|
|
671
|
+
});
|
|
672
|
+
});
|
|
673
|
+
}
|
|
674
|
+
else {
|
|
675
|
+
(_a = page.onReady) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
676
|
+
pageEl['__isReady'] = true;
|
|
677
|
+
}
|
|
581
678
|
onLoad && (pageEl['__page'] = page);
|
|
582
679
|
}
|
|
583
680
|
}
|
|
@@ -587,11 +684,14 @@ class MultiPageHandler {
|
|
|
587
684
|
return;
|
|
588
685
|
(_a = page.onLoad) === null || _a === void 0 ? void 0 : _a.call(page, this.getQuery('', page.options), () => {
|
|
589
686
|
var _a;
|
|
590
|
-
|
|
591
|
-
|
|
687
|
+
if (this.isTabBar) {
|
|
688
|
+
const pageEl = this.getPageContainer(page);
|
|
689
|
+
pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.add('taro_tabbar_page');
|
|
690
|
+
}
|
|
592
691
|
this.onReady(page, true);
|
|
593
692
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
594
|
-
this.bindPageEvents(page,
|
|
693
|
+
this.bindPageEvents(page, pageConfig);
|
|
694
|
+
this.triggerRouterChange();
|
|
595
695
|
});
|
|
596
696
|
}
|
|
597
697
|
getPageContainer(page) {
|
|
@@ -605,17 +705,33 @@ class MultiPageHandler {
|
|
|
605
705
|
? document.querySelector(`.taro_page#${id}`)
|
|
606
706
|
: document.querySelector('.taro_page') ||
|
|
607
707
|
document.querySelector('.taro_router'));
|
|
608
|
-
return el
|
|
708
|
+
return el;
|
|
709
|
+
}
|
|
710
|
+
getScrollingElement(page) {
|
|
711
|
+
if (this.usingWindowScroll)
|
|
712
|
+
return window;
|
|
713
|
+
return this.getPageContainer(page) || window;
|
|
609
714
|
}
|
|
610
|
-
bindPageEvents(page,
|
|
715
|
+
bindPageEvents(page, config = {}) {
|
|
611
716
|
var _a;
|
|
612
|
-
|
|
613
|
-
pageEl = this.getPageContainer();
|
|
614
|
-
}
|
|
717
|
+
const scrollEl = this.getScrollingElement(page);
|
|
615
718
|
const distance = config.onReachBottomDistance || ((_a = this.config.window) === null || _a === void 0 ? void 0 : _a.onReachBottomDistance) || 50;
|
|
616
|
-
bindPageScroll(page,
|
|
719
|
+
bindPageScroll(page, scrollEl, distance);
|
|
617
720
|
bindPageResize(page);
|
|
618
721
|
}
|
|
722
|
+
triggerRouterChange() {
|
|
723
|
+
/**
|
|
724
|
+
* @tarojs/runtime 中生命周期跑在 promise 中,所以这里需要 setTimeout 延迟事件调用
|
|
725
|
+
* TODO 考虑将生命周期返回 Promise,用于处理相关事件调用顺序
|
|
726
|
+
*/
|
|
727
|
+
setTimeout(() => {
|
|
728
|
+
runtime.eventCenter.trigger('__afterTaroRouterChange', {
|
|
729
|
+
toLocation: {
|
|
730
|
+
path: this.pathname
|
|
731
|
+
}
|
|
732
|
+
});
|
|
733
|
+
}, 0);
|
|
734
|
+
}
|
|
619
735
|
}
|
|
620
736
|
|
|
621
737
|
const createStampId$1 = runtime.incrementId();
|
|
@@ -631,6 +747,9 @@ const launchStampId$1 = createStampId$1();
|
|
|
631
747
|
function createMultiRouter(app, config, framework) {
|
|
632
748
|
var _a, _b, _c, _d, _e, _f;
|
|
633
749
|
return __awaiter(this, void 0, void 0, function* () {
|
|
750
|
+
if (typeof app.onUnhandledRejection === 'function') {
|
|
751
|
+
window.addEventListener('unhandledrejection', app.onUnhandledRejection);
|
|
752
|
+
}
|
|
634
753
|
RouterConfig.config = config;
|
|
635
754
|
const handler = new MultiPageHandler(config);
|
|
636
755
|
const launchParam = {
|
|
@@ -673,42 +792,12 @@ function createMultiRouter(app, config, framework) {
|
|
|
673
792
|
const loadConfig = Object.assign({}, pageConfig);
|
|
674
793
|
delete loadConfig['path'];
|
|
675
794
|
delete loadConfig['load'];
|
|
676
|
-
const page = runtime.createPageConfig(enablePullDownRefresh ? runtime.hooks.call('createPullDownComponent', el,
|
|
795
|
+
const page = runtime.createPageConfig(enablePullDownRefresh ? runtime.hooks.call('createPullDownComponent', el, pathName, framework, handler.PullDownRefresh) : el, pathName + runtime.stringify(launchParam), {}, loadConfig);
|
|
677
796
|
handler.load(page, pageConfig);
|
|
678
797
|
(_f = app.onShow) === null || _f === void 0 ? void 0 : _f.call(app, launchParam);
|
|
679
798
|
});
|
|
680
799
|
}
|
|
681
800
|
|
|
682
|
-
/**
|
|
683
|
-
* 插入页面动画需要的样式
|
|
684
|
-
*/
|
|
685
|
-
function loadAnimateStyle(ms = 300) {
|
|
686
|
-
const css = `
|
|
687
|
-
.taro_router .taro_page {
|
|
688
|
-
position: absolute;
|
|
689
|
-
left: 0;
|
|
690
|
-
top: 0;
|
|
691
|
-
width: 100%;
|
|
692
|
-
height: 100%;
|
|
693
|
-
background-color: #fff;
|
|
694
|
-
transform: translate(100%, 0);
|
|
695
|
-
transition: transform ${ms}ms;
|
|
696
|
-
z-index: 0;
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
.taro_router .taro_page.taro_tabbar_page,
|
|
700
|
-
.taro_router .taro_page.taro_page_show.taro_page_stationed {
|
|
701
|
-
transform: none;
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
.taro_router .taro_page.taro_page_show {
|
|
705
|
-
transform: translate(0, 0);
|
|
706
|
-
}`;
|
|
707
|
-
const style = document.createElement('style');
|
|
708
|
-
style.innerHTML = css;
|
|
709
|
-
document.getElementsByTagName('head')[0].appendChild(style);
|
|
710
|
-
}
|
|
711
|
-
|
|
712
801
|
/* eslint-disable dot-notation */
|
|
713
802
|
function setDisplay(el, type = '') {
|
|
714
803
|
if (el) {
|
|
@@ -794,6 +883,17 @@ class PageHandler {
|
|
|
794
883
|
}
|
|
795
884
|
return search.substring(1);
|
|
796
885
|
}
|
|
886
|
+
get usingWindowScroll() {
|
|
887
|
+
var _a;
|
|
888
|
+
let usingWindowScroll = false;
|
|
889
|
+
if (typeof ((_a = this.pageConfig) === null || _a === void 0 ? void 0 : _a.usingWindowScroll) === 'boolean') {
|
|
890
|
+
usingWindowScroll = this.pageConfig.usingWindowScroll;
|
|
891
|
+
}
|
|
892
|
+
const win = window;
|
|
893
|
+
win.__taroAppConfig || (win.__taroAppConfig = {});
|
|
894
|
+
win.__taroAppConfig.usingWindowScroll = usingWindowScroll;
|
|
895
|
+
return usingWindowScroll;
|
|
896
|
+
}
|
|
797
897
|
getQuery(stamp = '', search = '', options = {}) {
|
|
798
898
|
search = search ? `${search}&${this.search}` : this.search;
|
|
799
899
|
const query = search
|
|
@@ -804,7 +904,9 @@ class PageHandler {
|
|
|
804
904
|
}
|
|
805
905
|
mount() {
|
|
806
906
|
setHistoryMode(this.routerMode, this.router.basename);
|
|
907
|
+
this.pathname = exports.history.location.pathname;
|
|
807
908
|
this.animation && loadAnimateStyle(this.animationDuration);
|
|
909
|
+
loadRouterStyle(this.usingWindowScroll);
|
|
808
910
|
const appId = this.appId;
|
|
809
911
|
let app = document.getElementById(appId);
|
|
810
912
|
let isPosition = true;
|
|
@@ -871,7 +973,8 @@ class PageHandler {
|
|
|
871
973
|
this.isTabBar(this.pathname) && pageEl.classList.add('taro_tabbar_page');
|
|
872
974
|
this.addAnimation(pageEl, pageNo === 0);
|
|
873
975
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
874
|
-
this.bindPageEvents(page,
|
|
976
|
+
this.bindPageEvents(page, pageConfig);
|
|
977
|
+
this.triggerRouterChange();
|
|
875
978
|
}
|
|
876
979
|
else {
|
|
877
980
|
(_b = page.onLoad) === null || _b === void 0 ? void 0 : _b.call(page, param, () => {
|
|
@@ -881,7 +984,8 @@ class PageHandler {
|
|
|
881
984
|
this.addAnimation(pageEl, pageNo === 0);
|
|
882
985
|
this.onReady(page, true);
|
|
883
986
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
884
|
-
this.bindPageEvents(page,
|
|
987
|
+
this.bindPageEvents(page, pageConfig);
|
|
988
|
+
this.triggerRouterChange();
|
|
885
989
|
});
|
|
886
990
|
}
|
|
887
991
|
}
|
|
@@ -901,6 +1005,9 @@ class PageHandler {
|
|
|
901
1005
|
const pageEl = this.getPageContainer(page);
|
|
902
1006
|
pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.remove('taro_page_stationed');
|
|
903
1007
|
pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.remove('taro_page_show');
|
|
1008
|
+
if (pageEl) {
|
|
1009
|
+
pageEl.style.zIndex = '1';
|
|
1010
|
+
}
|
|
904
1011
|
this.unloadTimer = setTimeout(() => {
|
|
905
1012
|
var _a, _b;
|
|
906
1013
|
this.unloadTimer = null;
|
|
@@ -926,7 +1033,8 @@ class PageHandler {
|
|
|
926
1033
|
setDisplay(pageEl);
|
|
927
1034
|
this.addAnimation(pageEl, pageNo === 0);
|
|
928
1035
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
929
|
-
this.bindPageEvents(page,
|
|
1036
|
+
this.bindPageEvents(page, pageConfig);
|
|
1037
|
+
this.triggerRouterChange();
|
|
930
1038
|
}
|
|
931
1039
|
else {
|
|
932
1040
|
(_b = page.onLoad) === null || _b === void 0 ? void 0 : _b.call(page, param, () => {
|
|
@@ -935,7 +1043,8 @@ class PageHandler {
|
|
|
935
1043
|
this.addAnimation(pageEl, pageNo === 0);
|
|
936
1044
|
this.onReady(page, false);
|
|
937
1045
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
938
|
-
this.bindPageEvents(page,
|
|
1046
|
+
this.bindPageEvents(page, pageConfig);
|
|
1047
|
+
this.triggerRouterChange();
|
|
939
1048
|
});
|
|
940
1049
|
}
|
|
941
1050
|
}
|
|
@@ -989,23 +1098,42 @@ class PageHandler {
|
|
|
989
1098
|
? document.querySelector(`.taro_page#${id}`)
|
|
990
1099
|
: document.querySelector('.taro_page') ||
|
|
991
1100
|
document.querySelector('.taro_router'));
|
|
992
|
-
return el
|
|
1101
|
+
return el;
|
|
993
1102
|
}
|
|
994
|
-
|
|
1103
|
+
getScrollingElement(page) {
|
|
1104
|
+
if (this.usingWindowScroll)
|
|
1105
|
+
return window;
|
|
1106
|
+
return this.getPageContainer(page) || window;
|
|
1107
|
+
}
|
|
1108
|
+
bindPageEvents(page, config = {}) {
|
|
995
1109
|
var _a;
|
|
996
|
-
|
|
997
|
-
pageEl = this.getPageContainer();
|
|
998
|
-
}
|
|
1110
|
+
const scrollEl = this.getScrollingElement(page);
|
|
999
1111
|
const distance = config.onReachBottomDistance || ((_a = this.config.window) === null || _a === void 0 ? void 0 : _a.onReachBottomDistance) || 50;
|
|
1000
|
-
bindPageScroll(page,
|
|
1112
|
+
bindPageScroll(page, scrollEl, distance);
|
|
1001
1113
|
bindPageResize(page);
|
|
1002
1114
|
}
|
|
1115
|
+
triggerRouterChange() {
|
|
1116
|
+
/**
|
|
1117
|
+
* @tarojs/runtime 中生命周期跑在 promise 中,所以这里需要 setTimeout 延迟事件调用
|
|
1118
|
+
* TODO 考虑将生命周期返回 Promise,用于处理相关事件调用顺序
|
|
1119
|
+
*/
|
|
1120
|
+
setTimeout(() => {
|
|
1121
|
+
runtime.eventCenter.trigger('__afterTaroRouterChange', {
|
|
1122
|
+
toLocation: {
|
|
1123
|
+
path: this.pathname
|
|
1124
|
+
}
|
|
1125
|
+
});
|
|
1126
|
+
}, 0);
|
|
1127
|
+
}
|
|
1003
1128
|
}
|
|
1004
1129
|
|
|
1005
1130
|
const createStampId = runtime.incrementId();
|
|
1006
1131
|
let launchStampId = createStampId();
|
|
1007
1132
|
function createRouter(app, config, framework) {
|
|
1008
1133
|
var _a, _b;
|
|
1134
|
+
if (typeof app.onUnhandledRejection === 'function') {
|
|
1135
|
+
window.addEventListener('unhandledrejection', app.onUnhandledRejection);
|
|
1136
|
+
}
|
|
1009
1137
|
RouterConfig.config = config;
|
|
1010
1138
|
const handler = new PageHandler(config);
|
|
1011
1139
|
routesAlias.set(handler.router.customRoutes);
|
|
@@ -1030,8 +1158,10 @@ function createRouter(app, config, framework) {
|
|
|
1030
1158
|
(_a = app.onLaunch) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
|
|
1031
1159
|
app.onError && window.addEventListener('error', e => { var _a; return (_a = app.onError) === null || _a === void 0 ? void 0 : _a.call(app, e.message); });
|
|
1032
1160
|
const render = ({ location, action }) => __awaiter(this, void 0, void 0, function* () {
|
|
1033
|
-
var _c, _d, _e, _f, _g;
|
|
1161
|
+
var _c, _d, _e, _f, _g, _h;
|
|
1034
1162
|
handler.pathname = decodeURI(location.pathname);
|
|
1163
|
+
if ((_c = window.__taroAppConfig) === null || _c === void 0 ? void 0 : _c.usingWindowScroll)
|
|
1164
|
+
window.scrollTo(0, 0);
|
|
1035
1165
|
runtime.eventCenter.trigger('__taroRouterChange', {
|
|
1036
1166
|
toLocation: {
|
|
1037
1167
|
path: handler.pathname
|
|
@@ -1044,9 +1174,13 @@ function createRouter(app, config, framework) {
|
|
|
1044
1174
|
}
|
|
1045
1175
|
catch (error) {
|
|
1046
1176
|
if (error.status === 404) {
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1177
|
+
const notFoundEvent = {
|
|
1178
|
+
isEntryPage: stacks.length === 0,
|
|
1179
|
+
path: handler.pathname,
|
|
1180
|
+
query: handler.getQuery(createStampId()),
|
|
1181
|
+
};
|
|
1182
|
+
(_d = app.onPageNotFound) === null || _d === void 0 ? void 0 : _d.call(app, notFoundEvent);
|
|
1183
|
+
runtime.eventCenter.trigger('__taroRouterNotFound', notFoundEvent);
|
|
1050
1184
|
}
|
|
1051
1185
|
else if (/Loading hot update .* failed./.test(error.message)) {
|
|
1052
1186
|
// NOTE: webpack5 与 prebundle 搭配使用时,开发环境下初次启动时偶发错误,由于 HMR 加载 chunk hash 错误,导致热更新失败
|
|
@@ -1059,16 +1193,16 @@ function createRouter(app, config, framework) {
|
|
|
1059
1193
|
if (!element)
|
|
1060
1194
|
return;
|
|
1061
1195
|
const pageConfig = handler.pageConfig;
|
|
1062
|
-
let enablePullDownRefresh = ((
|
|
1196
|
+
let enablePullDownRefresh = ((_e = config === null || config === void 0 ? void 0 : config.window) === null || _e === void 0 ? void 0 : _e.enablePullDownRefresh) || false;
|
|
1063
1197
|
if (pageConfig) {
|
|
1064
|
-
setTitle((
|
|
1198
|
+
setTitle((_f = pageConfig.navigationBarTitleText) !== null && _f !== void 0 ? _f : document.title);
|
|
1065
1199
|
if (typeof pageConfig.enablePullDownRefresh === 'boolean') {
|
|
1066
1200
|
enablePullDownRefresh = pageConfig.enablePullDownRefresh;
|
|
1067
1201
|
}
|
|
1068
1202
|
}
|
|
1069
1203
|
const currentPage = runtime.Current.page;
|
|
1070
1204
|
const pathname = handler.pathname;
|
|
1071
|
-
const methodName = (
|
|
1205
|
+
const methodName = (_g = stacks.method) !== null && _g !== void 0 ? _g : '';
|
|
1072
1206
|
const cacheTabs = stacks.getTabs();
|
|
1073
1207
|
let shouldLoad = false;
|
|
1074
1208
|
stacks.method = '';
|
|
@@ -1093,11 +1227,11 @@ function createRouter(app, config, framework) {
|
|
|
1093
1227
|
else if (stacks.length > 0) {
|
|
1094
1228
|
const firstIns = stacks.getItem(0);
|
|
1095
1229
|
if (handler.isTabBar(firstIns.path)) {
|
|
1096
|
-
handler.unload(currentPage, stacks.length - 1);
|
|
1230
|
+
handler.unload(currentPage, stacks.length - 1, true);
|
|
1097
1231
|
stacks.pushTab(firstIns.path.split('?')[0]);
|
|
1098
1232
|
}
|
|
1099
1233
|
else {
|
|
1100
|
-
handler.unload(currentPage, stacks.length);
|
|
1234
|
+
handler.unload(currentPage, stacks.length, true);
|
|
1101
1235
|
}
|
|
1102
1236
|
}
|
|
1103
1237
|
if (cacheTabs[handler.pathname]) {
|
|
@@ -1132,7 +1266,7 @@ function createRouter(app, config, framework) {
|
|
|
1132
1266
|
shouldLoad = true;
|
|
1133
1267
|
}
|
|
1134
1268
|
if (shouldLoad || stacks.length < 1) {
|
|
1135
|
-
const el = (
|
|
1269
|
+
const el = (_h = element.default) !== null && _h !== void 0 ? _h : element;
|
|
1136
1270
|
const loadConfig = Object.assign({}, pageConfig);
|
|
1137
1271
|
const stacksIndex = stacks.length;
|
|
1138
1272
|
delete loadConfig['path'];
|
|
@@ -1145,16 +1279,11 @@ function createRouter(app, config, framework) {
|
|
|
1145
1279
|
else {
|
|
1146
1280
|
pageStampId = createStampId();
|
|
1147
1281
|
}
|
|
1148
|
-
const page = runtime.createPageConfig(enablePullDownRefresh ? runtime.hooks.call('createPullDownComponent', el,
|
|
1282
|
+
const page = runtime.createPageConfig(enablePullDownRefresh ? runtime.hooks.call('createPullDownComponent', el, pathname, framework, handler.PullDownRefresh, pageStampId) : el, pathname + runtime.stringify(handler.getQuery(pageStampId)), {}, loadConfig);
|
|
1149
1283
|
if (params)
|
|
1150
1284
|
page.options = params;
|
|
1151
1285
|
handler.load(page, pageConfig, pageStampId, stacksIndex);
|
|
1152
1286
|
}
|
|
1153
|
-
runtime.eventCenter.trigger('__afterTaroRouterChange', {
|
|
1154
|
-
toLocation: {
|
|
1155
|
-
path: handler.pathname
|
|
1156
|
-
}
|
|
1157
|
-
});
|
|
1158
1287
|
});
|
|
1159
1288
|
const routePath = addLeadingSlash(stripBasename(exports.history.location.pathname, handler.basename));
|
|
1160
1289
|
if (routePath === '/') {
|