@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.
package/dist/index.js CHANGED
@@ -81,9 +81,12 @@ prototypeAccessors.delta.set = function (delta) {
81
81
  if (delta > 0) {
82
82
  this.backDelta = delta;
83
83
  }
84
- else {
84
+ else if (this.backDelta > 0) {
85
85
  --this.backDelta;
86
86
  }
87
+ else {
88
+ this.backDelta = 0;
89
+ }
87
90
  };
88
91
  prototypeAccessors.length.get = function () {
89
92
  return this.stacks.length;
@@ -107,8 +110,9 @@ Stacks.prototype.getDelta = function getDelta (pathname) {
107
110
  if (this.backDelta >= 1) {
108
111
  return this.backDelta;
109
112
  }
113
+ var index = this.getLastIndex(pathname);
110
114
  // NOTE: 此处为了修复浏览器后退多级页面,在大量重复路由状况下可能出现判断错误的情况 (增强判断能力只能考虑在 query 中新增参数来判断,暂时搁置)
111
- return this.getLastIndex(pathname) || 1;
115
+ return index > 0 ? index : 1;
112
116
  };
113
117
  Stacks.prototype.getPrevIndex = function getPrevIndex (pathname, stateWith) {
114
118
  if ( stateWith === void 0 ) stateWith = 1;
@@ -1697,7 +1701,8 @@ PageHandler.prototype.onReady = function onReady (page, onLoad) {
1697
1701
  var el = pageEl.firstElementChild;
1698
1702
  (_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(function () {
1699
1703
  runtime.requestAnimationFrame(function () {
1700
- page.onReady();
1704
+ var _a;
1705
+ (_a = page.onReady) === null || _a === void 0 ? void 0 : _a.call(page);
1701
1706
  pageEl['__isReady'] = true;
1702
1707
  });
1703
1708
  });
@@ -1709,6 +1714,7 @@ PageHandler.prototype.load = function load (page, pageConfig, stacksIndex) {
1709
1714
  if ( pageConfig === void 0 ) pageConfig = {};
1710
1715
  if ( stacksIndex === void 0 ) stacksIndex = 0;
1711
1716
 
1717
+ var _a;
1712
1718
  if (!page)
1713
1719
  { return; }
1714
1720
  var pageEl = document.getElementById(page.path);
@@ -1726,7 +1732,7 @@ PageHandler.prototype.load = function load (page, pageConfig, stacksIndex) {
1726
1732
  });
1727
1733
  }
1728
1734
  stacks.push(page);
1729
- page.onShow();
1735
+ (_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
1730
1736
  bindPageScroll(page, pageConfig);
1731
1737
  };
1732
1738
  PageHandler.prototype.unload = function unload (page, delta, top) {
@@ -1754,6 +1760,11 @@ PageHandler.prototype.unload = function unload (page, delta, top) {
1754
1760
  (_a = this$1.lastUnloadPage) === null || _a === void 0 ? void 0 : _a.onUnload();
1755
1761
  }, this.animationDuration);
1756
1762
  }
1763
+ else {
1764
+ var pageEl$1 = document.getElementById(page.path);
1765
+ pageEl$1 === null || pageEl$1 === void 0 ? void 0 : pageEl$1.classList.remove('taro_page_show');
1766
+ page === null || page === void 0 ? void 0 : page.onUnload();
1767
+ }
1757
1768
  if (delta >= 1)
1758
1769
  { this.unload(stacks.last, delta); }
1759
1770
  };
@@ -1762,9 +1773,10 @@ PageHandler.prototype.show = function show (page, pageConfig, stacksIndex) {
1762
1773
  if ( pageConfig === void 0 ) pageConfig = {};
1763
1774
  if ( stacksIndex === void 0 ) stacksIndex = 0;
1764
1775
 
1776
+ var _a;
1765
1777
  if (!page)
1766
1778
  { return; }
1767
- page.onShow();
1779
+ (_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
1768
1780
  var pageEl = document.getElementById(page.path);
1769
1781
  if (pageEl) {
1770
1782
  setDisplay(pageEl);
@@ -1782,6 +1794,7 @@ PageHandler.prototype.show = function show (page, pageConfig, stacksIndex) {
1782
1794
  PageHandler.prototype.hide = function hide (page) {
1783
1795
  var this$1 = this;
1784
1796
 
1797
+ var _a;
1785
1798
  if (!page)
1786
1799
  { return; }
1787
1800
  // NOTE: 修复多页并发问题,此处可能因为路由跳转过快,执行时页面可能还没有创建成功
@@ -1797,7 +1810,7 @@ PageHandler.prototype.hide = function hide (page) {
1797
1810
  this$1.hideTimer = null;
1798
1811
  setDisplay(this$1.lastHidePage, 'none');
1799
1812
  }, this.animationDelay);
1800
- page.onHide();
1813
+ (_a = page.onHide) === null || _a === void 0 ? void 0 : _a.call(page);
1801
1814
  }
1802
1815
  else {
1803
1816
  setTimeout(function () { return this$1.hide(page); }, 0);
@@ -1822,7 +1835,7 @@ Object.defineProperties( PageHandler.prototype, prototypeAccessors$1 );
1822
1835
 
1823
1836
  /* eslint-disable dot-notation */
1824
1837
  function createRouter(app, config, framework) {
1825
- var _a;
1838
+ var _a, _b, _c;
1826
1839
  var handler = new PageHandler(config);
1827
1840
  var runtimeHooks = runtime.container.get(runtime.SERVICE_IDENTIFIER.Hooks);
1828
1841
  routesAlias.set(handler.router.customRoutes);
@@ -1833,7 +1846,7 @@ function createRouter(app, config, framework) {
1833
1846
  }); });
1834
1847
  var entryPagePath = config.entryPagePath || ((_a = routes[0].path) === null || _a === void 0 ? void 0 : _a[0]);
1835
1848
  var router = new UniversalRouter(routes, { baseUrl: basename || '' });
1836
- app.onLaunch();
1849
+ (_b = app.onLaunch) === null || _b === void 0 ? void 0 : _b.call(app);
1837
1850
  var render = async function (ref) {
1838
1851
  var location = ref.location;
1839
1852
  var action = ref.action;
@@ -1917,7 +1930,7 @@ function createRouter(app, config, framework) {
1917
1930
  exports.history.replace(prependBasename(entryPagePath + exports.history.location.search));
1918
1931
  }
1919
1932
  render({ location: exports.history.location, action: r.Push });
1920
- app.onShow(handler.getQuery(stacks.length));
1933
+ (_c = app.onShow) === null || _c === void 0 ? void 0 : _c.call(app, handler.getQuery(stacks.length));
1921
1934
  return exports.history.listen(render);
1922
1935
  }
1923
1936