@tarojs/router 3.3.18 → 3.3.19

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.
@@ -61,9 +61,12 @@ class Stacks {
61
61
  if (delta > 0) {
62
62
  this.backDelta = delta;
63
63
  }
64
- else {
64
+ else if (this.backDelta > 0) {
65
65
  --this.backDelta;
66
66
  }
67
+ else {
68
+ this.backDelta = 0;
69
+ }
67
70
  }
68
71
  get length() {
69
72
  return this.stacks.length;
@@ -85,8 +88,9 @@ class Stacks {
85
88
  if (this.backDelta >= 1) {
86
89
  return this.backDelta;
87
90
  }
91
+ const index = this.getLastIndex(pathname);
88
92
  // NOTE: 此处为了修复浏览器后退多级页面,在大量重复路由状况下可能出现判断错误的情况 (增强判断能力只能考虑在 query 中新增参数来判断,暂时搁置)
89
- return this.getLastIndex(pathname) || 1;
93
+ return index > 0 ? index : 1;
90
94
  }
91
95
  getPrevIndex(pathname, stateWith = 1) {
92
96
  const lastIndex = this.getLastIndex(pathname, stateWith);
@@ -1653,7 +1657,8 @@ class PageHandler {
1653
1657
  const el = pageEl.firstElementChild;
1654
1658
  (_b = (_a = el === null || el === void 0 ? void 0 : el['componentOnReady']) === null || _a === void 0 ? void 0 : _a.call(el)) === null || _b === void 0 ? void 0 : _b.then(() => {
1655
1659
  requestAnimationFrame(() => {
1656
- page.onReady();
1660
+ var _a;
1661
+ (_a = page.onReady) === null || _a === void 0 ? void 0 : _a.call(page);
1657
1662
  pageEl['__isReady'] = true;
1658
1663
  });
1659
1664
  });
@@ -1661,6 +1666,7 @@ class PageHandler {
1661
1666
  }
1662
1667
  }
1663
1668
  load(page, pageConfig = {}, stacksIndex = 0) {
1669
+ var _a;
1664
1670
  if (!page)
1665
1671
  return;
1666
1672
  let pageEl = document.getElementById(page.path);
@@ -1678,7 +1684,7 @@ class PageHandler {
1678
1684
  });
1679
1685
  }
1680
1686
  stacks.push(page);
1681
- page.onShow();
1687
+ (_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
1682
1688
  bindPageScroll(page, pageConfig);
1683
1689
  }
1684
1690
  unload(page, delta = 1, top = false) {
@@ -1702,13 +1708,19 @@ class PageHandler {
1702
1708
  (_a = this.lastUnloadPage) === null || _a === void 0 ? void 0 : _a.onUnload();
1703
1709
  }, this.animationDuration);
1704
1710
  }
1711
+ else {
1712
+ const pageEl = document.getElementById(page.path);
1713
+ pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.remove('taro_page_show');
1714
+ page === null || page === void 0 ? void 0 : page.onUnload();
1715
+ }
1705
1716
  if (delta >= 1)
1706
1717
  this.unload(stacks.last, delta);
1707
1718
  }
1708
1719
  show(page, pageConfig = {}, stacksIndex = 0) {
1720
+ var _a;
1709
1721
  if (!page)
1710
1722
  return;
1711
- page.onShow();
1723
+ (_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
1712
1724
  let pageEl = document.getElementById(page.path);
1713
1725
  if (pageEl) {
1714
1726
  setDisplay(pageEl);
@@ -1724,6 +1736,7 @@ class PageHandler {
1724
1736
  bindPageScroll(page, pageConfig);
1725
1737
  }
1726
1738
  hide(page) {
1739
+ var _a;
1727
1740
  if (!page)
1728
1741
  return;
1729
1742
  // NOTE: 修复多页并发问题,此处可能因为路由跳转过快,执行时页面可能还没有创建成功
@@ -1739,7 +1752,7 @@ class PageHandler {
1739
1752
  this.hideTimer = null;
1740
1753
  setDisplay(this.lastHidePage, 'none');
1741
1754
  }, this.animationDelay);
1742
- page.onHide();
1755
+ (_a = page.onHide) === null || _a === void 0 ? void 0 : _a.call(page);
1743
1756
  }
1744
1757
  else {
1745
1758
  setTimeout(() => this.hide(page), 0);
@@ -1761,7 +1774,7 @@ class PageHandler {
1761
1774
 
1762
1775
  /* eslint-disable dot-notation */
1763
1776
  function createRouter(app, config, framework) {
1764
- var _a;
1777
+ var _a, _b, _c;
1765
1778
  const handler = new PageHandler(config);
1766
1779
  const runtimeHooks = container.get(SERVICE_IDENTIFIER.Hooks);
1767
1780
  routesAlias.set(handler.router.customRoutes);
@@ -1772,7 +1785,7 @@ function createRouter(app, config, framework) {
1772
1785
  }));
1773
1786
  const entryPagePath = config.entryPagePath || ((_a = routes[0].path) === null || _a === void 0 ? void 0 : _a[0]);
1774
1787
  const router = new UniversalRouter(routes, { baseUrl: basename || '' });
1775
- app.onLaunch();
1788
+ (_b = app.onLaunch) === null || _b === void 0 ? void 0 : _b.call(app);
1776
1789
  const render = async ({ location, action }) => {
1777
1790
  var _a, _b, _c, _d;
1778
1791
  handler.pathname = location.pathname;
@@ -1853,7 +1866,7 @@ function createRouter(app, config, framework) {
1853
1866
  history.replace(prependBasename(entryPagePath + history.location.search));
1854
1867
  }
1855
1868
  render({ location: history.location, action: r.Push });
1856
- app.onShow(handler.getQuery(stacks.length));
1869
+ (_c = app.onShow) === null || _c === void 0 ? void 0 : _c.call(app, handler.getQuery(stacks.length));
1857
1870
  return history.listen(render);
1858
1871
  }
1859
1872