@tarojs/router 3.6.28 → 3.6.30

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/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,20 +53,6 @@ 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') {
70
57
  history.push(pathPieces, state);
71
58
  }
package/dist/index.cjs.js CHANGED
@@ -32,6 +32,7 @@ body {
32
32
  .taro_router > .taro_page.taro_tabbar_page,
33
33
  .taro_router > .taro_page.taro_page_show.taro_page_stationed {
34
34
  transform: none;
35
+ transition: none;
35
36
  }
36
37
 
37
38
  .taro_router > .taro_page.taro_page_show {
@@ -71,8 +72,9 @@ ${enableTabBar ? `
71
72
  }
72
73
 
73
74
  ` : ''}
74
- .taro_page_shade,
75
- .taro_router > .taro_page.taro_page_show.taro_page_stationed:not(.taro_page_shade):not(.taro_tabbar_page):not(:last-child) {
75
+ .taro_page_shade:has(+.taro_page_stationed),
76
+ .taro_page_shade.taro_tabbar_page,
77
+ .taro_router > .taro_page.taro_page_show.taro_page_stationed:not(.taro_page_shade):not(.taro_tabbar_page):not(:last-child):has(+.taro_page_stationed) {
76
78
  display: none;
77
79
  }
78
80
  `;
@@ -262,8 +264,9 @@ class RouterConfig {
262
264
  return this.router.mode || 'hash';
263
265
  }
264
266
  static get customRoutes() { return this.router.customRoutes || {}; }
267
+ // 这个方法不考虑 basename 和 customRoutes,只判断原始的 url 是否在 pages 中
265
268
  static isPage(url = '') {
266
- return this.pages.findIndex(e => prependBasename(e) === url) !== -1;
269
+ return this.pages.findIndex(e => runtime.addLeadingSlash(e) === url) !== -1;
267
270
  }
268
271
  }
269
272
 
@@ -532,13 +535,14 @@ function processNavigateUrl(option) {
532
535
  const parts = routesAlias.getOrigin(exports.history.location.pathname).split('/');
533
536
  parts.pop();
534
537
  pathPieces.pathname.split('/').forEach((item) => {
535
- if (item === '.') {
538
+ if (item === '.')
536
539
  return;
537
- }
538
540
  item === '..' ? parts.pop() : parts.push(item);
539
541
  });
540
542
  pathPieces.pathname = parts.join('/');
541
543
  }
544
+ // 确保是 / 开头的路径
545
+ pathPieces.pathname = runtime.addLeadingSlash(pathPieces.pathname);
542
546
  // 处理自定义路由
543
547
  pathPieces.pathname = routesAlias.getAlias(runtime.addLeadingSlash(pathPieces.pathname));
544
548
  // 处理 basename
@@ -568,20 +572,6 @@ function navigate(option, method) {
568
572
  if ('url' in option) {
569
573
  const pathPieces = processNavigateUrl(option);
570
574
  const state = { timestamp: Date.now() };
571
- if (pathPieces.pathname) {
572
- const originPath = routesAlias.getOrigin(pathPieces.pathname);
573
- if (!RouterConfig.isPage(runtime.addLeadingSlash(originPath)) && !RouterConfig.isPage(runtime.addLeadingSlash(pathPieces.pathname))) {
574
- const res = { errMsg: `${method}:fail page ${originPath} is not found` };
575
- fail === null || fail === void 0 ? void 0 : fail(res);
576
- complete === null || complete === void 0 ? void 0 : complete(res);
577
- if (fail || complete) {
578
- return resolve(res);
579
- }
580
- else {
581
- return reject(res);
582
- }
583
- }
584
- }
585
575
  if (method === 'navigateTo') {
586
576
  exports.history.push(pathPieces, state);
587
577
  }
@@ -926,7 +916,7 @@ class NavigationBarHandler {
926
916
  });
927
917
  }
928
918
  toHomeFn() {
929
- reLaunch({ url: this.pageContext.homePage });
919
+ reLaunch({ url: this.pageContext.originHomePage });
930
920
  }
931
921
  backFn() {
932
922
  navigateBack();
@@ -975,7 +965,7 @@ class NavigationBarHandler {
975
965
  this.setNavigationLoading();
976
966
  }
977
967
  setCacheValue() {
978
- const currentPage = this.pageContext.currentPage;
968
+ const currentPage = this.pageContext.originPathname;
979
969
  if (typeof this.cache[currentPage] !== 'object') {
980
970
  this.cache[currentPage] = {};
981
971
  }
@@ -1006,7 +996,7 @@ class NavigationBarHandler {
1006
996
  var _a;
1007
997
  if (!this.navigationBarElement)
1008
998
  return;
1009
- const currentPage = this.pageContext.currentPage;
999
+ const currentPage = this.pageContext.originPathname;
1010
1000
  let isShow;
1011
1001
  if (typeof show === 'boolean') {
1012
1002
  isShow = show;
@@ -1031,7 +1021,7 @@ class NavigationBarHandler {
1031
1021
  var _a, _b, _c;
1032
1022
  if (!this.navigationBarElement)
1033
1023
  return;
1034
- const currentPage = this.pageContext.currentPage;
1024
+ const currentPage = this.pageContext.originPathname;
1035
1025
  let color;
1036
1026
  if (typeof backgroundColor === 'string') {
1037
1027
  color = backgroundColor;
@@ -1055,7 +1045,7 @@ class NavigationBarHandler {
1055
1045
  var _a, _b, _c;
1056
1046
  if (!this.navigationBarElement)
1057
1047
  return;
1058
- const currentPage = this.pageContext.currentPage;
1048
+ const currentPage = this.pageContext.originPathname;
1059
1049
  let color;
1060
1050
  if (typeof fontColor === 'string') {
1061
1051
  color = fontColor;
@@ -1077,7 +1067,7 @@ class NavigationBarHandler {
1077
1067
  }
1078
1068
  setTitle(title) {
1079
1069
  var _a, _b, _c;
1080
- const currentPage = this.pageContext.currentPage;
1070
+ const currentPage = this.pageContext.originPathname;
1081
1071
  let proceedTitle;
1082
1072
  if (typeof title === 'string') {
1083
1073
  proceedTitle = title;
@@ -1158,6 +1148,7 @@ class PageHandler {
1158
1148
  this.defaultAnimation = { duration: 300, delay: 50 };
1159
1149
  this.config = config;
1160
1150
  this.homePage = runtime.getHomePage(this.routes[0].path, this.basename, this.customRoutes, this.config.entryPagePath);
1151
+ this.originHomePage = this.config.entryPagePath || this.routes[0].path || this.basename;
1161
1152
  this.mount();
1162
1153
  this.navigationBarHandler = new NavigationBarHandler(this);
1163
1154
  }
@@ -1191,14 +1182,14 @@ class PageHandler {
1191
1182
  }
1192
1183
  set pathname(p) { this.router.pathname = p; }
1193
1184
  get pathname() { return this.router.pathname; }
1185
+ // Note: 把 pathname 转换为原始路径,主要是处理 customRoutes 和 basename
1186
+ get originPathname() { return routesAlias.getOrigin(runtime.addLeadingSlash(runtime.stripBasename(this.pathname, this.basename))); }
1194
1187
  get basename() { return this.router.basename || ''; }
1195
1188
  get pageConfig() {
1196
- const routePath = runtime.addLeadingSlash(runtime.stripBasename(this.pathname, this.basename));
1197
1189
  const homePage = runtime.addLeadingSlash(this.homePage);
1198
1190
  return this.routes.find(r => {
1199
- var _a;
1200
1191
  const pagePath = runtime.addLeadingSlash(r.path);
1201
- return [pagePath, homePage].includes(routePath) || ((_a = routesAlias.getConfig(pagePath)) === null || _a === void 0 ? void 0 : _a.includes(routePath));
1192
+ return [pagePath, homePage].includes(this.originPathname);
1202
1193
  });
1203
1194
  }
1204
1195
  isTabBar(pathname) {
@@ -1388,24 +1379,35 @@ class PageHandler {
1388
1379
  });
1389
1380
  }
1390
1381
  }
1391
- hide(page) {
1392
- var _a;
1382
+ hide(page, animation = false) {
1383
+ var _a, _b, _c, _d, _e, _f, _g;
1393
1384
  if (!page)
1394
1385
  return;
1395
1386
  // NOTE: 修复多页并发问题,此处可能因为路由跳转过快,执行时页面可能还没有创建成功
1396
1387
  const pageEl = this.getPageContainer(page);
1397
1388
  if (pageEl) {
1398
- if (this.hideTimer) {
1399
- clearTimeout(this.hideTimer);
1400
- this.hideTimer = null;
1401
- pageEl.classList.add('taro_page_shade');
1389
+ if (animation) {
1390
+ if (this.hideTimer) {
1391
+ clearTimeout(this.hideTimer);
1392
+ this.hideTimer = null;
1393
+ (_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');
1394
+ }
1395
+ this.lastHidePage = pageEl;
1396
+ this.hideTimer = setTimeout(() => {
1397
+ this.hideTimer = null;
1398
+ pageEl.classList.add('taro_page_shade');
1399
+ }, this.animationDuration + this.animationDelay);
1400
+ (_d = page.onHide) === null || _d === void 0 ? void 0 : _d.call(page);
1402
1401
  }
1403
- this.lastHidePage = pageEl;
1404
- this.hideTimer = setTimeout(() => {
1405
- this.hideTimer = null;
1402
+ else {
1403
+ if (this.hideTimer) {
1404
+ clearTimeout(this.hideTimer);
1405
+ this.hideTimer = null;
1406
+ (_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');
1407
+ }
1406
1408
  pageEl.classList.add('taro_page_shade');
1407
- }, this.animationDuration + this.animationDelay);
1408
- (_a = page.onHide) === null || _a === void 0 ? void 0 : _a.call(page);
1409
+ this.lastHidePage = pageEl;
1410
+ }
1409
1411
  }
1410
1412
  else {
1411
1413
  setTimeout(() => this.hide(page), 0);
@@ -1573,6 +1575,7 @@ function createRouter(history$1, app, config, framework) {
1573
1575
  if (handler.isSamePage(currentPage))
1574
1576
  return;
1575
1577
  if (handler.isTabBar(currentPage.path)) {
1578
+ // NOTE: 从 tabBar 页面切换到 tabBar 页面
1576
1579
  handler.hide(currentPage);
1577
1580
  stacks.pushTab(currentPage.path.split('?')[0]);
1578
1581
  }
@@ -1616,7 +1619,7 @@ function createRouter(history$1, app, config, framework) {
1616
1619
  shouldLoad = true;
1617
1620
  }
1618
1621
  else if (action === 'PUSH') {
1619
- handler.hide(currentPage);
1622
+ handler.hide(currentPage, true);
1620
1623
  shouldLoad = true;
1621
1624
  }
1622
1625
  if (shouldLoad || stacks.length < 1) {
package/dist/index.esm.js CHANGED
@@ -31,6 +31,7 @@ body {
31
31
  .taro_router > .taro_page.taro_tabbar_page,
32
32
  .taro_router > .taro_page.taro_page_show.taro_page_stationed {
33
33
  transform: none;
34
+ transition: none;
34
35
  }
35
36
 
36
37
  .taro_router > .taro_page.taro_page_show {
@@ -70,8 +71,9 @@ ${enableTabBar ? `
70
71
  }
71
72
 
72
73
  ` : ''}
73
- .taro_page_shade,
74
- .taro_router > .taro_page.taro_page_show.taro_page_stationed:not(.taro_page_shade):not(.taro_tabbar_page):not(:last-child) {
74
+ .taro_page_shade:has(+.taro_page_stationed),
75
+ .taro_page_shade.taro_tabbar_page,
76
+ .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) {
75
77
  display: none;
76
78
  }
77
79
  `;
@@ -261,8 +263,9 @@ class RouterConfig {
261
263
  return this.router.mode || 'hash';
262
264
  }
263
265
  static get customRoutes() { return this.router.customRoutes || {}; }
266
+ // 这个方法不考虑 basename 和 customRoutes,只判断原始的 url 是否在 pages 中
264
267
  static isPage(url = '') {
265
- return this.pages.findIndex(e => prependBasename(e) === url) !== -1;
268
+ return this.pages.findIndex(e => addLeadingSlash(e) === url) !== -1;
266
269
  }
267
270
  }
268
271
 
@@ -531,13 +534,14 @@ function processNavigateUrl(option) {
531
534
  const parts = routesAlias.getOrigin(history.location.pathname).split('/');
532
535
  parts.pop();
533
536
  pathPieces.pathname.split('/').forEach((item) => {
534
- if (item === '.') {
537
+ if (item === '.')
535
538
  return;
536
- }
537
539
  item === '..' ? parts.pop() : parts.push(item);
538
540
  });
539
541
  pathPieces.pathname = parts.join('/');
540
542
  }
543
+ // 确保是 / 开头的路径
544
+ pathPieces.pathname = addLeadingSlash(pathPieces.pathname);
541
545
  // 处理自定义路由
542
546
  pathPieces.pathname = routesAlias.getAlias(addLeadingSlash(pathPieces.pathname));
543
547
  // 处理 basename
@@ -567,20 +571,6 @@ function navigate(option, method) {
567
571
  if ('url' in option) {
568
572
  const pathPieces = processNavigateUrl(option);
569
573
  const state = { timestamp: Date.now() };
570
- if (pathPieces.pathname) {
571
- const originPath = routesAlias.getOrigin(pathPieces.pathname);
572
- if (!RouterConfig.isPage(addLeadingSlash(originPath)) && !RouterConfig.isPage(addLeadingSlash(pathPieces.pathname))) {
573
- const res = { errMsg: `${method}:fail page ${originPath} is not found` };
574
- fail === null || fail === void 0 ? void 0 : fail(res);
575
- complete === null || complete === void 0 ? void 0 : complete(res);
576
- if (fail || complete) {
577
- return resolve(res);
578
- }
579
- else {
580
- return reject(res);
581
- }
582
- }
583
- }
584
574
  if (method === 'navigateTo') {
585
575
  history.push(pathPieces, state);
586
576
  }
@@ -925,7 +915,7 @@ class NavigationBarHandler {
925
915
  });
926
916
  }
927
917
  toHomeFn() {
928
- reLaunch({ url: this.pageContext.homePage });
918
+ reLaunch({ url: this.pageContext.originHomePage });
929
919
  }
930
920
  backFn() {
931
921
  navigateBack();
@@ -974,7 +964,7 @@ class NavigationBarHandler {
974
964
  this.setNavigationLoading();
975
965
  }
976
966
  setCacheValue() {
977
- const currentPage = this.pageContext.currentPage;
967
+ const currentPage = this.pageContext.originPathname;
978
968
  if (typeof this.cache[currentPage] !== 'object') {
979
969
  this.cache[currentPage] = {};
980
970
  }
@@ -1005,7 +995,7 @@ class NavigationBarHandler {
1005
995
  var _a;
1006
996
  if (!this.navigationBarElement)
1007
997
  return;
1008
- const currentPage = this.pageContext.currentPage;
998
+ const currentPage = this.pageContext.originPathname;
1009
999
  let isShow;
1010
1000
  if (typeof show === 'boolean') {
1011
1001
  isShow = show;
@@ -1030,7 +1020,7 @@ class NavigationBarHandler {
1030
1020
  var _a, _b, _c;
1031
1021
  if (!this.navigationBarElement)
1032
1022
  return;
1033
- const currentPage = this.pageContext.currentPage;
1023
+ const currentPage = this.pageContext.originPathname;
1034
1024
  let color;
1035
1025
  if (typeof backgroundColor === 'string') {
1036
1026
  color = backgroundColor;
@@ -1054,7 +1044,7 @@ class NavigationBarHandler {
1054
1044
  var _a, _b, _c;
1055
1045
  if (!this.navigationBarElement)
1056
1046
  return;
1057
- const currentPage = this.pageContext.currentPage;
1047
+ const currentPage = this.pageContext.originPathname;
1058
1048
  let color;
1059
1049
  if (typeof fontColor === 'string') {
1060
1050
  color = fontColor;
@@ -1076,7 +1066,7 @@ class NavigationBarHandler {
1076
1066
  }
1077
1067
  setTitle(title) {
1078
1068
  var _a, _b, _c;
1079
- const currentPage = this.pageContext.currentPage;
1069
+ const currentPage = this.pageContext.originPathname;
1080
1070
  let proceedTitle;
1081
1071
  if (typeof title === 'string') {
1082
1072
  proceedTitle = title;
@@ -1157,6 +1147,7 @@ class PageHandler {
1157
1147
  this.defaultAnimation = { duration: 300, delay: 50 };
1158
1148
  this.config = config;
1159
1149
  this.homePage = getHomePage(this.routes[0].path, this.basename, this.customRoutes, this.config.entryPagePath);
1150
+ this.originHomePage = this.config.entryPagePath || this.routes[0].path || this.basename;
1160
1151
  this.mount();
1161
1152
  this.navigationBarHandler = new NavigationBarHandler(this);
1162
1153
  }
@@ -1190,14 +1181,14 @@ class PageHandler {
1190
1181
  }
1191
1182
  set pathname(p) { this.router.pathname = p; }
1192
1183
  get pathname() { return this.router.pathname; }
1184
+ // Note: 把 pathname 转换为原始路径,主要是处理 customRoutes 和 basename
1185
+ get originPathname() { return routesAlias.getOrigin(addLeadingSlash(stripBasename(this.pathname, this.basename))); }
1193
1186
  get basename() { return this.router.basename || ''; }
1194
1187
  get pageConfig() {
1195
- const routePath = addLeadingSlash(stripBasename(this.pathname, this.basename));
1196
1188
  const homePage = addLeadingSlash(this.homePage);
1197
1189
  return this.routes.find(r => {
1198
- var _a;
1199
1190
  const pagePath = addLeadingSlash(r.path);
1200
- return [pagePath, homePage].includes(routePath) || ((_a = routesAlias.getConfig(pagePath)) === null || _a === void 0 ? void 0 : _a.includes(routePath));
1191
+ return [pagePath, homePage].includes(this.originPathname);
1201
1192
  });
1202
1193
  }
1203
1194
  isTabBar(pathname) {
@@ -1387,24 +1378,35 @@ class PageHandler {
1387
1378
  });
1388
1379
  }
1389
1380
  }
1390
- hide(page) {
1391
- var _a;
1381
+ hide(page, animation = false) {
1382
+ var _a, _b, _c, _d, _e, _f, _g;
1392
1383
  if (!page)
1393
1384
  return;
1394
1385
  // NOTE: 修复多页并发问题,此处可能因为路由跳转过快,执行时页面可能还没有创建成功
1395
1386
  const pageEl = this.getPageContainer(page);
1396
1387
  if (pageEl) {
1397
- if (this.hideTimer) {
1398
- clearTimeout(this.hideTimer);
1399
- this.hideTimer = null;
1400
- pageEl.classList.add('taro_page_shade');
1388
+ if (animation) {
1389
+ if (this.hideTimer) {
1390
+ clearTimeout(this.hideTimer);
1391
+ this.hideTimer = null;
1392
+ (_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');
1393
+ }
1394
+ this.lastHidePage = pageEl;
1395
+ this.hideTimer = setTimeout(() => {
1396
+ this.hideTimer = null;
1397
+ pageEl.classList.add('taro_page_shade');
1398
+ }, this.animationDuration + this.animationDelay);
1399
+ (_d = page.onHide) === null || _d === void 0 ? void 0 : _d.call(page);
1401
1400
  }
1402
- this.lastHidePage = pageEl;
1403
- this.hideTimer = setTimeout(() => {
1404
- this.hideTimer = null;
1401
+ else {
1402
+ if (this.hideTimer) {
1403
+ clearTimeout(this.hideTimer);
1404
+ this.hideTimer = null;
1405
+ (_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');
1406
+ }
1405
1407
  pageEl.classList.add('taro_page_shade');
1406
- }, this.animationDuration + this.animationDelay);
1407
- (_a = page.onHide) === null || _a === void 0 ? void 0 : _a.call(page);
1408
+ this.lastHidePage = pageEl;
1409
+ }
1408
1410
  }
1409
1411
  else {
1410
1412
  setTimeout(() => this.hide(page), 0);
@@ -1572,6 +1574,7 @@ function createRouter(history, app, config, framework) {
1572
1574
  if (handler.isSamePage(currentPage))
1573
1575
  return;
1574
1576
  if (handler.isTabBar(currentPage.path)) {
1577
+ // NOTE: 从 tabBar 页面切换到 tabBar 页面
1575
1578
  handler.hide(currentPage);
1576
1579
  stacks.pushTab(currentPage.path.split('?')[0]);
1577
1580
  }
@@ -1615,7 +1618,7 @@ function createRouter(history, app, config, framework) {
1615
1618
  shouldLoad = true;
1616
1619
  }
1617
1620
  else if (action === 'PUSH') {
1618
- handler.hide(currentPage);
1621
+ handler.hide(currentPage, true);
1619
1622
  shouldLoad = true;
1620
1623
  }
1621
1624
  if (shouldLoad || stacks.length < 1) {
@@ -7,6 +7,7 @@ declare class RouterConfig {
7
7
  static get router(): import("../types/router").Router;
8
8
  static get mode(): "hash" | "browser" | "multi";
9
9
  static get customRoutes(): Record<string, string | string[]>;
10
+ // 这个方法不考虑 basename 和 customRoutes,只判断原始的 url 是否在 pages 中
10
11
  static isPage(url?: string): boolean;
11
12
  }
12
13
  export { RouterConfig };
@@ -1,4 +1,4 @@
1
- import { prependBasename } from '../history.js';
1
+ import { addLeadingSlash } from '@tarojs/runtime';
2
2
 
3
3
  class RouterConfig {
4
4
  static set config(e) {
@@ -17,8 +17,9 @@ class RouterConfig {
17
17
  return this.router.mode || 'hash';
18
18
  }
19
19
  static get customRoutes() { return this.router.customRoutes || {}; }
20
+ // 这个方法不考虑 basename 和 customRoutes,只判断原始的 url 是否在 pages 中
20
21
  static isPage(url = '') {
21
- return this.pages.findIndex(e => prependBasename(e) === url) !== -1;
22
+ return this.pages.findIndex(e => addLeadingSlash(e) === url) !== -1;
22
23
  }
23
24
  }
24
25
 
@@ -24,7 +24,7 @@ class NavigationBarHandler {
24
24
  });
25
25
  }
26
26
  toHomeFn() {
27
- reLaunch({ url: this.pageContext.homePage });
27
+ reLaunch({ url: this.pageContext.originHomePage });
28
28
  }
29
29
  backFn() {
30
30
  navigateBack();
@@ -73,7 +73,7 @@ class NavigationBarHandler {
73
73
  this.setNavigationLoading();
74
74
  }
75
75
  setCacheValue() {
76
- const currentPage = this.pageContext.currentPage;
76
+ const currentPage = this.pageContext.originPathname;
77
77
  if (typeof this.cache[currentPage] !== 'object') {
78
78
  this.cache[currentPage] = {};
79
79
  }
@@ -104,7 +104,7 @@ class NavigationBarHandler {
104
104
  var _a;
105
105
  if (!this.navigationBarElement)
106
106
  return;
107
- const currentPage = this.pageContext.currentPage;
107
+ const currentPage = this.pageContext.originPathname;
108
108
  let isShow;
109
109
  if (typeof show === 'boolean') {
110
110
  isShow = show;
@@ -129,7 +129,7 @@ class NavigationBarHandler {
129
129
  var _a, _b, _c;
130
130
  if (!this.navigationBarElement)
131
131
  return;
132
- const currentPage = this.pageContext.currentPage;
132
+ const currentPage = this.pageContext.originPathname;
133
133
  let color;
134
134
  if (typeof backgroundColor === 'string') {
135
135
  color = backgroundColor;
@@ -153,7 +153,7 @@ class NavigationBarHandler {
153
153
  var _a, _b, _c;
154
154
  if (!this.navigationBarElement)
155
155
  return;
156
- const currentPage = this.pageContext.currentPage;
156
+ const currentPage = this.pageContext.originPathname;
157
157
  let color;
158
158
  if (typeof fontColor === 'string') {
159
159
  color = fontColor;
@@ -175,7 +175,7 @@ class NavigationBarHandler {
175
175
  }
176
176
  setTitle(title) {
177
177
  var _a, _b, _c;
178
- const currentPage = this.pageContext.currentPage;
178
+ const currentPage = this.pageContext.originPathname;
179
179
  let proceedTitle;
180
180
  if (typeof title === 'string') {
181
181
  proceedTitle = title;
@@ -13,6 +13,7 @@ declare class PageHandler {
13
13
  protected lastUnloadPage: PageInstance | null;
14
14
  protected navigationBarHandler: NavigationBarHandler;
15
15
  homePage: string;
16
+ originHomePage: string;
16
17
  constructor(config: SpaRouterConfig, history: History);
17
18
  get currentPage(): string;
18
19
  get appId(): string;
@@ -27,6 +28,7 @@ declare class PageHandler {
27
28
  get animationDuration(): number;
28
29
  set pathname(p: string);
29
30
  get pathname(): string;
31
+ get originPathname(): string;
30
32
  get basename(): string;
31
33
  get pageConfig(): Route | undefined;
32
34
  isTabBar(pathname: string): boolean;
@@ -42,7 +44,7 @@ declare class PageHandler {
42
44
  load(page: PageInstance, pageConfig: Route | undefined, stampId: string, pageNo?: number): void;
43
45
  unload(page?: PageInstance | null, delta?: number, top?: boolean): void;
44
46
  show(page?: PageInstance | null, pageConfig?: Route, pageNo?: number): void;
45
- hide(page?: PageInstance | null): void;
47
+ hide(page?: PageInstance | null, animation?: boolean): void;
46
48
  addAnimation(pageEl?: HTMLElement | null, first?: boolean): void;
47
49
  getPageContainer(page?: PageInstance | null): HTMLElement | null;
48
50
  getScrollingElement(page?: PageInstance | null): HTMLElement | (Window & typeof globalThis);
@@ -15,6 +15,7 @@ class PageHandler {
15
15
  this.defaultAnimation = { duration: 300, delay: 50 };
16
16
  this.config = config;
17
17
  this.homePage = getHomePage(this.routes[0].path, this.basename, this.customRoutes, this.config.entryPagePath);
18
+ this.originHomePage = this.config.entryPagePath || this.routes[0].path || this.basename;
18
19
  this.mount();
19
20
  this.navigationBarHandler = new NavigationBarHandler(this);
20
21
  }
@@ -48,14 +49,14 @@ class PageHandler {
48
49
  }
49
50
  set pathname(p) { this.router.pathname = p; }
50
51
  get pathname() { return this.router.pathname; }
52
+ // Note: 把 pathname 转换为原始路径,主要是处理 customRoutes 和 basename
53
+ get originPathname() { return routesAlias.getOrigin(addLeadingSlash(stripBasename(this.pathname, this.basename))); }
51
54
  get basename() { return this.router.basename || ''; }
52
55
  get pageConfig() {
53
- const routePath = addLeadingSlash(stripBasename(this.pathname, this.basename));
54
56
  const homePage = addLeadingSlash(this.homePage);
55
57
  return this.routes.find(r => {
56
- var _a;
57
58
  const pagePath = addLeadingSlash(r.path);
58
- return [pagePath, homePage].includes(routePath) || ((_a = routesAlias.getConfig(pagePath)) === null || _a === void 0 ? void 0 : _a.includes(routePath));
59
+ return [pagePath, homePage].includes(this.originPathname);
59
60
  });
60
61
  }
61
62
  isTabBar(pathname) {
@@ -245,24 +246,35 @@ class PageHandler {
245
246
  });
246
247
  }
247
248
  }
248
- hide(page) {
249
- var _a;
249
+ hide(page, animation = false) {
250
+ var _a, _b, _c, _d, _e, _f, _g;
250
251
  if (!page)
251
252
  return;
252
253
  // NOTE: 修复多页并发问题,此处可能因为路由跳转过快,执行时页面可能还没有创建成功
253
254
  const pageEl = this.getPageContainer(page);
254
255
  if (pageEl) {
255
- if (this.hideTimer) {
256
- clearTimeout(this.hideTimer);
257
- this.hideTimer = null;
258
- pageEl.classList.add('taro_page_shade');
256
+ if (animation) {
257
+ if (this.hideTimer) {
258
+ clearTimeout(this.hideTimer);
259
+ this.hideTimer = null;
260
+ (_c = (_b = (_a = this.lastHidePage) === null || _a === void 0 ? void 0 : _a.classList) === null || _b === void 0 ? void 0 : _b.add) === null || _c === void 0 ? void 0 : _c.call(_b, 'taro_page_shade');
261
+ }
262
+ this.lastHidePage = pageEl;
263
+ this.hideTimer = setTimeout(() => {
264
+ this.hideTimer = null;
265
+ pageEl.classList.add('taro_page_shade');
266
+ }, this.animationDuration + this.animationDelay);
267
+ (_d = page.onHide) === null || _d === void 0 ? void 0 : _d.call(page);
259
268
  }
260
- this.lastHidePage = pageEl;
261
- this.hideTimer = setTimeout(() => {
262
- this.hideTimer = null;
269
+ else {
270
+ if (this.hideTimer) {
271
+ clearTimeout(this.hideTimer);
272
+ this.hideTimer = null;
273
+ (_g = (_f = (_e = this.lastHidePage) === null || _e === void 0 ? void 0 : _e.classList) === null || _f === void 0 ? void 0 : _f.add) === null || _g === void 0 ? void 0 : _g.call(_f, 'taro_page_shade');
274
+ }
263
275
  pageEl.classList.add('taro_page_shade');
264
- }, this.animationDuration + this.animationDelay);
265
- (_a = page.onHide) === null || _a === void 0 ? void 0 : _a.call(page);
276
+ this.lastHidePage = pageEl;
277
+ }
266
278
  }
267
279
  else {
268
280
  setTimeout(() => this.hide(page), 0);
@@ -114,6 +114,7 @@ function createRouter(history, app, config, framework) {
114
114
  if (handler.isSamePage(currentPage))
115
115
  return;
116
116
  if (handler.isTabBar(currentPage.path)) {
117
+ // NOTE: 从 tabBar 页面切换到 tabBar 页面
117
118
  handler.hide(currentPage);
118
119
  stacks.pushTab(currentPage.path.split('?')[0]);
119
120
  }
@@ -157,7 +158,7 @@ function createRouter(history, app, config, framework) {
157
158
  shouldLoad = true;
158
159
  }
159
160
  else if (action === 'PUSH') {
160
- handler.hide(currentPage);
161
+ handler.hide(currentPage, true);
161
162
  shouldLoad = true;
162
163
  }
163
164
  if (shouldLoad || stacks.length < 1) {
package/dist/style.js CHANGED
@@ -21,6 +21,7 @@ body {
21
21
  .taro_router > .taro_page.taro_tabbar_page,
22
22
  .taro_router > .taro_page.taro_page_show.taro_page_stationed {
23
23
  transform: none;
24
+ transition: none;
24
25
  }
25
26
 
26
27
  .taro_router > .taro_page.taro_page_show {
@@ -60,8 +61,9 @@ ${enableTabBar ? `
60
61
  }
61
62
 
62
63
  ` : ''}
63
- .taro_page_shade,
64
- .taro_router > .taro_page.taro_page_show.taro_page_stationed:not(.taro_page_shade):not(.taro_tabbar_page):not(:last-child) {
64
+ .taro_page_shade:has(+.taro_page_stationed),
65
+ .taro_page_shade.taro_tabbar_page,
66
+ .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) {
65
67
  display: none;
66
68
  }
67
69
  `;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tarojs/router",
3
- "version": "3.6.28",
3
+ "version": "3.6.30",
4
4
  "description": "Taro-router",
5
5
  "browser": "dist/index.js",
6
6
  "main:h5": "dist/index.esm.js",
@@ -44,14 +44,14 @@
44
44
  "rollup-plugin-ts": "^3.0.2",
45
45
  "ts-jest": "^29.0.5",
46
46
  "typescript": "^4.7.4",
47
- "@tarojs/taro": "3.6.28",
48
- "@tarojs/runtime": "3.6.28",
49
- "@tarojs/shared": "3.6.28"
47
+ "@tarojs/runtime": "3.6.30",
48
+ "@tarojs/shared": "3.6.30",
49
+ "@tarojs/taro": "3.6.30"
50
50
  },
51
51
  "peerDependencies": {
52
- "@tarojs/taro": "3.6.28",
53
- "@tarojs/runtime": "3.6.28",
54
- "@tarojs/shared": "3.6.28"
52
+ "@tarojs/runtime": "3.6.30",
53
+ "@tarojs/shared": "3.6.30",
54
+ "@tarojs/taro": "3.6.30"
55
55
  },
56
56
  "scripts": {
57
57
  "prebuild": "pnpm run clean",