@tarojs/router 4.0.0-beta.92 → 4.0.0-beta.94

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 CHANGED
@@ -154,15 +154,8 @@ See `/LICENSE` for details of the license.
154
154
 
155
155
  ==================
156
156
 
157
- MIT (stencil-vue2-output-target):
158
- The following files embed [stencil-vue2-output-target](https://github.com/diondree/stencil-vue2-output-target) MIT:
159
- `/packages/taro-components-library-vue2/src/vue-component-lib/utils.ts`
160
- See `/LICENSE` for details of the license.
161
-
162
- ==================
163
-
164
157
  MIT (weui):
165
- The following files embed [stencil-vue2-output-target](https://github.com/Tencent/weui) MIT:
158
+ The following files embed [weui](https://github.com/Tencent/weui) MIT:
166
159
  `/packages/taro-components/src/components/*.scss`
167
160
  See `/LICENSE.txt` for details of the license.
168
161
 
@@ -172,3 +165,10 @@ Apache-2.0 (intersection-observer):
172
165
  The following files embed [intersection-observer](https://github.com/GoogleChromeLabs/intersection-observer) Apache-2.0:
173
166
  `/packages/taro-api/src/polyfill/intersection-observer.ts`
174
167
  See `/LICENSE.txt` for details of the license.
168
+
169
+ ==================
170
+
171
+ MIT (babel-plugin-jsx-dom-expressions):
172
+ The following files embed [babel-plugin-jsx-dom-expressions](https://github.com/ryansolid/dom-expressions/blob/main/packages/babel-plugin-jsx-dom-expressions) MIT:
173
+ `/packages/babel-plugin-transform-solid-jsx/src/*`
174
+ See `/LICENSE` for details of the license.
package/dist/api.d.ts CHANGED
@@ -1,8 +1,7 @@
1
1
  import Taro from '@tarojs/taro';
2
- declare function navigateTo(option: Taro.navigateTo.Option): ReturnType<typeof Taro.navigateTo>;
3
- declare function redirectTo(option: Taro.redirectTo.Option): ReturnType<typeof Taro.redirectTo>;
4
- declare function navigateBack(option?: Taro.navigateBack.Option): ReturnType<typeof Taro.navigateBack>;
5
- declare function switchTab(option: Taro.switchTab.Option): ReturnType<typeof Taro.switchTab>;
6
- declare function reLaunch(option: Taro.reLaunch.Option): ReturnType<typeof Taro.reLaunch>;
7
- declare function getCurrentPages(): Taro.Page[];
8
- export { navigateTo, redirectTo, navigateBack, switchTab, reLaunch, getCurrentPages };
2
+ export declare function navigateTo(option: Taro.navigateTo.Option): ReturnType<typeof Taro.navigateTo>;
3
+ export declare function redirectTo(option: Taro.redirectTo.Option): ReturnType<typeof Taro.redirectTo>;
4
+ export declare function navigateBack(option?: Taro.navigateBack.Option): ReturnType<typeof Taro.navigateBack>;
5
+ export declare function switchTab(option: Taro.switchTab.Option): ReturnType<typeof Taro.switchTab>;
6
+ export declare function reLaunch(option: Taro.reLaunch.Option): ReturnType<typeof Taro.reLaunch>;
7
+ export declare function getCurrentPages(): Taro.Page[];
package/dist/api.js CHANGED
@@ -16,13 +16,14 @@ function processNavigateUrl(option) {
16
16
  const parts = routesAlias.getOrigin(history.location.pathname).split('/');
17
17
  parts.pop();
18
18
  pathPieces.pathname.split('/').forEach((item) => {
19
- if (item === '.') {
19
+ if (item === '.')
20
20
  return;
21
- }
22
21
  item === '..' ? parts.pop() : parts.push(item);
23
22
  });
24
23
  pathPieces.pathname = parts.join('/');
25
24
  }
25
+ // 确保是 / 开头的路径
26
+ pathPieces.pathname = addLeadingSlash(pathPieces.pathname);
26
27
  // 处理自定义路由
27
28
  pathPieces.pathname = routesAlias.getAlias(addLeadingSlash(pathPieces.pathname));
28
29
  // 处理 basename
@@ -52,21 +53,8 @@ function navigate(option, method) {
52
53
  if ('url' in option) {
53
54
  const pathPieces = processNavigateUrl(option);
54
55
  const state = { timestamp: Date.now() };
55
- if (pathPieces.pathname) {
56
- const originPath = routesAlias.getOrigin(pathPieces.pathname);
57
- if (!RouterConfig.isPage(addLeadingSlash(originPath)) && !RouterConfig.isPage(addLeadingSlash(pathPieces.pathname))) {
58
- const res = { errMsg: `${method}:fail page ${originPath} is not found` };
59
- fail === null || fail === void 0 ? void 0 : fail(res);
60
- complete === null || complete === void 0 ? void 0 : complete(res);
61
- if (fail || complete) {
62
- return resolve(res);
63
- }
64
- else {
65
- return reject(res);
66
- }
67
- }
68
- }
69
56
  if (method === 'navigateTo') {
57
+ // Note: 由于 spa 会针对弱网情况下,短时间内多次跳转同一个页面跳转加了锁,后续如果有用户反馈返回无效,那可能是这个问题
70
58
  history.push(pathPieces, state);
71
59
  }
72
60
  else if (method === 'redirectTo' || method === 'switchTab') {
@@ -1,3 +1,2 @@
1
- import { PageInstance } from '@tarojs/runtime';
2
- declare function bindPageResize(page: PageInstance): void;
3
- export { bindPageResize };
1
+ import type { PageInstance } from '@tarojs/runtime';
2
+ export declare function bindPageResize(page: PageInstance): void;
@@ -1,3 +1,2 @@
1
- import { PageInstance } from '@tarojs/runtime';
2
- declare function bindPageScroll(page: PageInstance, scrollEl: HTMLElement | Window, distance?: number): void;
3
- export { bindPageScroll };
1
+ import type { PageInstance } from '@tarojs/runtime';
2
+ export declare function bindPageScroll(page: PageInstance, scrollEl: HTMLElement | Window, distance?: number): void;
package/dist/history.d.ts CHANGED
@@ -1,6 +1,8 @@
1
- import { IH5RouterConfig } from '@tarojs/taro/types/compile';
2
- import { StateEvent } from '../types/history';
3
- declare let history: History;
1
+ import { Action, createBrowserHistory, createHashHistory } from 'history';
2
+ import type { IH5RouterConfig } from '@tarojs/taro/types/compile';
3
+ import type { Blocker, BrowserHistoryOptions, HashHistoryOptions, History, Listener, Location, Path, To } from 'history';
4
+ import type { StateEvent } from '../types/history';
5
+ export declare let history: History;
4
6
  declare class MpaHistory implements History {
5
7
  action: Action;
6
8
  get location(): Location;
@@ -17,8 +19,8 @@ declare class MpaHistory implements History {
17
19
  replaceState: globalThis.History['replaceState'];
18
20
  eventState(action: Required<StateEvent>['action']): (data: any, unused: string, url?: string | URL | null) => any;
19
21
  }
20
- declare function setHistory(h: History, base?: string): void;
21
- declare function createMpaHistory(_?: HashHistoryOptions | BrowserHistoryOptions): MpaHistory;
22
- declare function setHistoryMode(mode?: IH5RouterConfig['mode'], base?: string): void;
23
- declare function prependBasename(url?: string): string;
24
- export { history, setHistory, createMpaHistory, createBrowserHistory, createHashHistory, setHistoryMode, prependBasename };
22
+ export declare function setHistory(h: History, base?: string): void;
23
+ export declare function createMpaHistory(_?: HashHistoryOptions | BrowserHistoryOptions): MpaHistory;
24
+ export { createBrowserHistory, createHashHistory };
25
+ export declare function setHistoryMode(mode?: IH5RouterConfig['mode'], base?: string): void;
26
+ export declare function prependBasename(url?: string): string;
package/dist/index.cjs.js CHANGED
@@ -15,7 +15,8 @@ var UniversalRouter = require('universal-router');
15
15
  function loadAnimateStyle(ms = 300) {
16
16
  const css = `
17
17
  body {
18
- overflow: hidden; // 防止 iOS 页面滚动
18
+ /* 防止 iOS 页面滚动 */
19
+ overflow: hidden;
19
20
  }
20
21
  .taro_router > .taro_page {
21
22
  position: absolute;
@@ -72,8 +73,9 @@ ${enableTabBar ? `
72
73
  }
73
74
 
74
75
  ` : ''}
75
- .taro_page_shade,
76
- .taro_router > .taro_page.taro_page_show.taro_page_stationed:not(.taro_page_shade):not(.taro_tabbar_page):not(:last-child) {
76
+ .taro_page_shade:has(+.taro_page_stationed),
77
+ .taro_page_shade.taro_tabbar_page,
78
+ .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) {
77
79
  display: none;
78
80
  }
79
81
  `;
@@ -141,7 +143,7 @@ function loadNavigationBarStyle() {
141
143
  to {
142
144
  transform: rotate(360deg);
143
145
  }
144
- }
146
+ }
145
147
 
146
148
  .taro-navigation-bar-no-icon > .taro-navigation-bar-home {
147
149
  display: none;
@@ -263,8 +265,9 @@ class RouterConfig {
263
265
  return this.router.mode || 'hash';
264
266
  }
265
267
  static get customRoutes() { return this.router.customRoutes || {}; }
268
+ // 这个方法不考虑 basename 和 customRoutes,只判断原始的 url 是否在 pages 中
266
269
  static isPage(url = '') {
267
- return this.pages.findIndex(e => prependBasename(e) === url) !== -1;
270
+ return this.pages.findIndex(e => runtime.addLeadingSlash(e) === url) !== -1;
268
271
  }
269
272
  }
270
273
 
@@ -533,13 +536,14 @@ function processNavigateUrl(option) {
533
536
  const parts = routesAlias.getOrigin(exports.history.location.pathname).split('/');
534
537
  parts.pop();
535
538
  pathPieces.pathname.split('/').forEach((item) => {
536
- if (item === '.') {
539
+ if (item === '.')
537
540
  return;
538
- }
539
541
  item === '..' ? parts.pop() : parts.push(item);
540
542
  });
541
543
  pathPieces.pathname = parts.join('/');
542
544
  }
545
+ // 确保是 / 开头的路径
546
+ pathPieces.pathname = runtime.addLeadingSlash(pathPieces.pathname);
543
547
  // 处理自定义路由
544
548
  pathPieces.pathname = routesAlias.getAlias(runtime.addLeadingSlash(pathPieces.pathname));
545
549
  // 处理 basename
@@ -569,21 +573,8 @@ function navigate(option, method) {
569
573
  if ('url' in option) {
570
574
  const pathPieces = processNavigateUrl(option);
571
575
  const state = { timestamp: Date.now() };
572
- if (pathPieces.pathname) {
573
- const originPath = routesAlias.getOrigin(pathPieces.pathname);
574
- if (!RouterConfig.isPage(runtime.addLeadingSlash(originPath)) && !RouterConfig.isPage(runtime.addLeadingSlash(pathPieces.pathname))) {
575
- const res = { errMsg: `${method}:fail page ${originPath} is not found` };
576
- fail === null || fail === void 0 ? void 0 : fail(res);
577
- complete === null || complete === void 0 ? void 0 : complete(res);
578
- if (fail || complete) {
579
- return resolve(res);
580
- }
581
- else {
582
- return reject(res);
583
- }
584
- }
585
- }
586
576
  if (method === 'navigateTo') {
577
+ // Note: 由于 spa 会针对弱网情况下,短时间内多次跳转同一个页面跳转加了锁,后续如果有用户反馈返回无效,那可能是这个问题
587
578
  exports.history.push(pathPieces, state);
588
579
  }
589
580
  else if (method === 'redirectTo' || method === 'switchTab') {
@@ -853,8 +844,8 @@ const launchStampId$1 = createStampId$1();
853
844
  * - 不支持路由动画
854
845
  */
855
846
  function createMultiRouter(history, app, config, framework) {
856
- var _a, _b, _c, _d, _e, _f;
857
847
  return tslib.__awaiter(this, void 0, void 0, function* () {
848
+ var _a, _b, _c, _d, _e, _f;
858
849
  if (typeof app.onUnhandledRejection === 'function') {
859
850
  window.addEventListener('unhandledrejection', app.onUnhandledRejection);
860
851
  }
@@ -862,7 +853,7 @@ function createMultiRouter(history, app, config, framework) {
862
853
  RouterConfig.config = config;
863
854
  const handler = new MultiPageHandler(config, history);
864
855
  const launchParam = {
865
- path: config.pageName,
856
+ path: config.pageName, // 多页面模式没新开一个页面相当于重启,所以直接使用当前页面路径
866
857
  query: handler.getQuery(launchStampId$1),
867
858
  scene: 0,
868
859
  shareTicket: '',
@@ -941,7 +932,7 @@ class NavigationBarHandler {
941
932
  });
942
933
  }
943
934
  toHomeFn() {
944
- reLaunch({ url: this.pageContext.homePage });
935
+ reLaunch({ url: this.pageContext.originHomePage });
945
936
  }
946
937
  backFn() {
947
938
  navigateBack();
@@ -990,7 +981,7 @@ class NavigationBarHandler {
990
981
  this.setNavigationLoading();
991
982
  }
992
983
  setCacheValue() {
993
- const currentPage = this.pageContext.currentPage;
984
+ const currentPage = this.pageContext.originPathname;
994
985
  if (typeof this.cache[currentPage] !== 'object') {
995
986
  this.cache[currentPage] = {};
996
987
  }
@@ -1021,7 +1012,7 @@ class NavigationBarHandler {
1021
1012
  var _a;
1022
1013
  if (!this.navigationBarElement)
1023
1014
  return;
1024
- const currentPage = this.pageContext.currentPage;
1015
+ const currentPage = this.pageContext.originPathname;
1025
1016
  let isShow;
1026
1017
  if (typeof show === 'boolean') {
1027
1018
  isShow = show;
@@ -1046,7 +1037,7 @@ class NavigationBarHandler {
1046
1037
  var _a, _b, _c;
1047
1038
  if (!this.navigationBarElement)
1048
1039
  return;
1049
- const currentPage = this.pageContext.currentPage;
1040
+ const currentPage = this.pageContext.originPathname;
1050
1041
  let color;
1051
1042
  if (typeof backgroundColor === 'string') {
1052
1043
  color = backgroundColor;
@@ -1070,7 +1061,7 @@ class NavigationBarHandler {
1070
1061
  var _a, _b, _c;
1071
1062
  if (!this.navigationBarElement)
1072
1063
  return;
1073
- const currentPage = this.pageContext.currentPage;
1064
+ const currentPage = this.pageContext.originPathname;
1074
1065
  let color;
1075
1066
  if (typeof fontColor === 'string') {
1076
1067
  color = fontColor;
@@ -1092,7 +1083,7 @@ class NavigationBarHandler {
1092
1083
  }
1093
1084
  setTitle(title) {
1094
1085
  var _a, _b, _c;
1095
- const currentPage = this.pageContext.currentPage;
1086
+ const currentPage = this.pageContext.originPathname;
1096
1087
  let proceedTitle;
1097
1088
  if (typeof title === 'string') {
1098
1089
  proceedTitle = title;
@@ -1173,6 +1164,7 @@ class PageHandler {
1173
1164
  this.defaultAnimation = { duration: 300, delay: 50 };
1174
1165
  this.config = config;
1175
1166
  this.homePage = runtime.getHomePage(this.routes[0].path, this.basename, this.customRoutes, this.config.entryPagePath);
1167
+ this.originHomePage = this.config.entryPagePath || this.routes[0].path || this.basename;
1176
1168
  this.mount();
1177
1169
  this.navigationBarHandler = new NavigationBarHandler(this);
1178
1170
  }
@@ -1206,14 +1198,14 @@ class PageHandler {
1206
1198
  }
1207
1199
  set pathname(p) { this.router.pathname = p; }
1208
1200
  get pathname() { return this.router.pathname; }
1201
+ // Note: 把 pathname 转换为原始路径,主要是处理 customRoutes 和 basename
1202
+ get originPathname() { return routesAlias.getOrigin(runtime.addLeadingSlash(runtime.stripBasename(this.pathname, this.basename))); }
1209
1203
  get basename() { return this.router.basename || ''; }
1210
1204
  get pageConfig() {
1211
- const routePath = runtime.addLeadingSlash(runtime.stripBasename(this.pathname, this.basename));
1212
1205
  const homePage = runtime.addLeadingSlash(this.homePage);
1213
1206
  return this.routes.find(r => {
1214
- var _a;
1215
1207
  const pagePath = runtime.addLeadingSlash(r.path);
1216
- return [pagePath, homePage].includes(routePath) || ((_a = routesAlias.getConfig(pagePath)) === null || _a === void 0 ? void 0 : _a.includes(routePath));
1208
+ return [pagePath, homePage].includes(this.originPathname);
1217
1209
  });
1218
1210
  }
1219
1211
  isTabBar(pathname) {
@@ -1403,24 +1395,35 @@ class PageHandler {
1403
1395
  });
1404
1396
  }
1405
1397
  }
1406
- hide(page) {
1407
- var _a;
1398
+ hide(page, animation = false) {
1399
+ var _a, _b, _c, _d, _e, _f, _g;
1408
1400
  if (!page)
1409
1401
  return;
1410
1402
  // NOTE: 修复多页并发问题,此处可能因为路由跳转过快,执行时页面可能还没有创建成功
1411
1403
  const pageEl = this.getPageContainer(page);
1412
1404
  if (pageEl) {
1413
- if (this.hideTimer) {
1414
- clearTimeout(this.hideTimer);
1415
- this.hideTimer = null;
1416
- pageEl.classList.add('taro_page_shade');
1405
+ if (animation) {
1406
+ if (this.hideTimer) {
1407
+ clearTimeout(this.hideTimer);
1408
+ this.hideTimer = null;
1409
+ (_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');
1410
+ }
1411
+ this.lastHidePage = pageEl;
1412
+ this.hideTimer = setTimeout(() => {
1413
+ this.hideTimer = null;
1414
+ pageEl.classList.add('taro_page_shade');
1415
+ }, this.animationDuration + this.animationDelay);
1416
+ (_d = page.onHide) === null || _d === void 0 ? void 0 : _d.call(page);
1417
1417
  }
1418
- this.lastHidePage = pageEl;
1419
- this.hideTimer = setTimeout(() => {
1420
- this.hideTimer = null;
1418
+ else {
1419
+ if (this.hideTimer) {
1420
+ clearTimeout(this.hideTimer);
1421
+ this.hideTimer = null;
1422
+ (_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');
1423
+ }
1421
1424
  pageEl.classList.add('taro_page_shade');
1422
- }, this.animationDuration + this.animationDelay);
1423
- (_a = page.onHide) === null || _a === void 0 ? void 0 : _a.call(page);
1425
+ this.lastHidePage = pageEl;
1426
+ }
1424
1427
  }
1425
1428
  else {
1426
1429
  setTimeout(() => this.hide(page), 0);
@@ -1491,6 +1494,10 @@ function createRouter(history$1, app, config, framework) {
1491
1494
  }
1492
1495
  RouterConfig.config = config;
1493
1496
  const handler = new PageHandler(config, history$1);
1497
+ // Note: 弱网情况下,快速切换 tab,会造成同个页面实例被多次挂在到页面上,原因是资源请求是异步的,短时间内发起多个请求,
1498
+ // 会在资源加载完成后,同时走到挂载的逻辑,造成 pageStampId 更新不及时,两个 page 的Id 相同,后面很多操作是通过 getElementById 来进行的
1499
+ // 所以需要加一个锁来应对这个情况
1500
+ const pageLock = {};
1494
1501
  routesAlias.set(handler.router.customRoutes);
1495
1502
  const basename = handler.router.basename;
1496
1503
  const routes = handler.routes.map(route => {
@@ -1512,29 +1519,35 @@ function createRouter(history$1, app, config, framework) {
1512
1519
  runtime.eventCenter.trigger('__taroRouterLaunch', launchParam);
1513
1520
  (_a = app.onLaunch) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
1514
1521
  app.onError && window.addEventListener('error', e => { var _a; return (_a = app.onError) === null || _a === void 0 ? void 0 : _a.call(app, e.message); });
1515
- const render = ({ location, action }) => tslib.__awaiter(this, void 0, void 0, function* () {
1516
- var _c, _d, _e, _f, _g, _h, _j, _k;
1517
- handler.pathname = decodeURI(location.pathname);
1518
- if ((_c = window.__taroAppConfig) === null || _c === void 0 ? void 0 : _c.usingWindowScroll)
1522
+ const render = (_c) => tslib.__awaiter(this, [_c], void 0, function* ({ location, action }) {
1523
+ var _d, _e, _f, _g, _h, _j, _k, _l;
1524
+ // Note: 由于下面有异步加载操作 先不要在这里去设置 handler.pathname
1525
+ const currentPathname = decodeURI(location.pathname);
1526
+ if ((_d = window.__taroAppConfig) === null || _d === void 0 ? void 0 : _d.usingWindowScroll)
1519
1527
  window.scrollTo(0, 0);
1520
1528
  runtime.eventCenter.trigger('__taroRouterChange', {
1521
1529
  toLocation: {
1522
- path: handler.pathname
1530
+ path: currentPathname
1523
1531
  }
1524
1532
  });
1525
- let element, params;
1533
+ let element, context, params;
1534
+ const routerPath = handler.router.forcePath || currentPathname;
1535
+ pageLock[routerPath] = typeof pageLock[routerPath] === 'number' ? pageLock[routerPath] + 1 : 1;
1536
+ const currentLock = pageLock[routerPath];
1537
+ let postLock;
1526
1538
  try {
1527
- const result = yield router.resolve(handler.router.forcePath || handler.pathname);
1528
- [element, , params] = yield Promise.all(result);
1539
+ const result = yield router.resolve(routerPath);
1540
+ [element, context, params] = yield Promise.all(result);
1541
+ postLock = pageLock[routerPath];
1529
1542
  }
1530
1543
  catch (error) {
1531
1544
  if (error.status === 404) {
1532
1545
  const notFoundEvent = {
1533
1546
  isEntryPage: stacks.length === 0,
1534
- path: handler.pathname,
1547
+ path: currentPathname,
1535
1548
  query: handler.getQuery(createStampId()),
1536
1549
  };
1537
- (_d = app.onPageNotFound) === null || _d === void 0 ? void 0 : _d.call(app, notFoundEvent);
1550
+ (_e = app.onPageNotFound) === null || _e === void 0 ? void 0 : _e.call(app, notFoundEvent);
1538
1551
  runtime.eventCenter.trigger('__taroRouterNotFound', notFoundEvent);
1539
1552
  }
1540
1553
  else if (/Loading hot update .* failed./.test(error.message)) {
@@ -1545,13 +1558,16 @@ function createRouter(history$1, app, config, framework) {
1545
1558
  throw error;
1546
1559
  }
1547
1560
  }
1548
- if (!element)
1561
+ if (!element || currentLock !== postLock)
1549
1562
  return;
1550
- const pageConfig = handler.pageConfig;
1551
- let enablePullDownRefresh = ((_e = config === null || config === void 0 ? void 0 : config.window) === null || _e === void 0 ? void 0 : _e.enablePullDownRefresh) || false;
1552
- let navigationStyle = ((_f = config === null || config === void 0 ? void 0 : config.window) === null || _f === void 0 ? void 0 : _f.navigationStyle) || 'default';
1553
- let navigationBarTextStyle = ((_g = config === null || config === void 0 ? void 0 : config.window) === null || _g === void 0 ? void 0 : _g.navigationBarTextStyle) || 'white';
1554
- let navigationBarBackgroundColor = ((_h = config === null || config === void 0 ? void 0 : config.window) === null || _h === void 0 ? void 0 : _h.navigationBarBackgroundColor) || '#000000';
1563
+ // Note: 异步结束后,在设置 handler.pathname
1564
+ // context.pathname universal-router 被处理过了,是发起资源请求的时候传入的 pathname,即 await router.resolve(routerPath) 这个 routerPath
1565
+ handler.pathname = context.pathname;
1566
+ const { pathname, pageConfig } = handler;
1567
+ let enablePullDownRefresh = ((_f = config === null || config === void 0 ? void 0 : config.window) === null || _f === void 0 ? void 0 : _f.enablePullDownRefresh) || false;
1568
+ let navigationStyle = ((_g = config === null || config === void 0 ? void 0 : config.window) === null || _g === void 0 ? void 0 : _g.navigationStyle) || 'default';
1569
+ let navigationBarTextStyle = ((_h = config === null || config === void 0 ? void 0 : config.window) === null || _h === void 0 ? void 0 : _h.navigationBarTextStyle) || 'white';
1570
+ let navigationBarBackgroundColor = ((_j = config === null || config === void 0 ? void 0 : config.window) === null || _j === void 0 ? void 0 : _j.navigationBarBackgroundColor) || '#000000';
1555
1571
  if (pageConfig) {
1556
1572
  if (typeof pageConfig.enablePullDownRefresh === 'boolean') {
1557
1573
  enablePullDownRefresh = pageConfig.enablePullDownRefresh;
@@ -1568,8 +1584,7 @@ function createRouter(history$1, app, config, framework) {
1568
1584
  }
1569
1585
  runtime.eventCenter.trigger('__taroSetNavigationStyle', navigationStyle, navigationBarTextStyle, navigationBarBackgroundColor);
1570
1586
  const currentPage = runtime.Current.page;
1571
- const pathname = handler.pathname;
1572
- const methodName = (_j = stacks.method) !== null && _j !== void 0 ? _j : '';
1587
+ const methodName = (_k = stacks.method) !== null && _k !== void 0 ? _k : '';
1573
1588
  const cacheTabs = stacks.getTabs();
1574
1589
  let shouldLoad = false;
1575
1590
  stacks.method = '';
@@ -1584,10 +1599,11 @@ function createRouter(history$1, app, config, framework) {
1584
1599
  }
1585
1600
  shouldLoad = true;
1586
1601
  }
1587
- else if (currentPage && handler.isTabBar(handler.pathname)) {
1602
+ else if (currentPage && handler.isTabBar(pathname)) {
1588
1603
  if (handler.isSamePage(currentPage))
1589
1604
  return;
1590
1605
  if (handler.isTabBar(currentPage.path)) {
1606
+ // NOTE: 从 tabBar 页面切换到 tabBar 页面
1591
1607
  handler.hide(currentPage);
1592
1608
  stacks.pushTab(currentPage.path.split('?')[0]);
1593
1609
  }
@@ -1601,8 +1617,8 @@ function createRouter(history$1, app, config, framework) {
1601
1617
  handler.unload(currentPage, stacks.length, true);
1602
1618
  }
1603
1619
  }
1604
- if (cacheTabs[handler.pathname]) {
1605
- stacks.popTab(handler.pathname);
1620
+ if (cacheTabs[pathname]) {
1621
+ stacks.popTab(pathname);
1606
1622
  return handler.show(stacks.getItem(0), pageConfig, 0);
1607
1623
  }
1608
1624
  shouldLoad = true;
@@ -1631,11 +1647,11 @@ function createRouter(history$1, app, config, framework) {
1631
1647
  shouldLoad = true;
1632
1648
  }
1633
1649
  else if (action === 'PUSH') {
1634
- handler.hide(currentPage);
1650
+ handler.hide(currentPage, true);
1635
1651
  shouldLoad = true;
1636
1652
  }
1637
1653
  if (shouldLoad || stacks.length < 1) {
1638
- const el = (_k = element.default) !== null && _k !== void 0 ? _k : element;
1654
+ const el = (_l = element.default) !== null && _l !== void 0 ? _l : element;
1639
1655
  const loadConfig = Object.assign({}, pageConfig);
1640
1656
  const stacksIndex = stacks.length;
1641
1657
  delete loadConfig['path'];
@@ -1724,11 +1740,11 @@ function handleAppMountWithTabbar(config, history, appId = config.appId || 'app'
1724
1740
  initNavigationBar(config, container);
1725
1741
  }
1726
1742
 
1727
- Object.defineProperty(exports, 'createBrowserHistory', {
1743
+ Object.defineProperty(exports, "createBrowserHistory", {
1728
1744
  enumerable: true,
1729
1745
  get: function () { return history.createBrowserHistory; }
1730
1746
  });
1731
- Object.defineProperty(exports, 'createHashHistory', {
1747
+ Object.defineProperty(exports, "createHashHistory", {
1732
1748
  enumerable: true,
1733
1749
  get: function () { return history.createHashHistory; }
1734
1750
  });
package/dist/index.d.ts CHANGED
@@ -1,10 +1,9 @@
1
- import { History } from "./history.js";
2
- import { MpaRouterConfig, SpaRouterConfig } from '../types/router';
3
- declare function handleAppMount(config: SpaRouterConfig | MpaRouterConfig, _: History, appId?: string): void;
4
- declare function handleAppMountWithTabbar(config: SpaRouterConfig | MpaRouterConfig, history: History, appId?: string): void;
5
- export * from "./api.js";
6
- export * from "./history.js";
7
- export { createMultiRouter } from "./router/mpa.js";
8
- export { createRouter } from "./router/spa.js";
9
- export * from "./utils/index.js";
10
- export { handleAppMount, handleAppMountWithTabbar };
1
+ import type { History } from 'history';
2
+ import type { MpaRouterConfig, SpaRouterConfig } from '../types/router';
3
+ export * from './api';
4
+ export * from './history';
5
+ export { createMultiRouter } from './router/mpa';
6
+ export { createRouter } from './router/spa';
7
+ export * from './utils';
8
+ export declare function handleAppMount(config: SpaRouterConfig | MpaRouterConfig, _: History, appId?: string): void;
9
+ export declare function handleAppMountWithTabbar(config: SpaRouterConfig | MpaRouterConfig, history: History, appId?: string): void;