@tarojs/taro-h5 3.3.8 → 3.3.12

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.
Files changed (2) hide show
  1. package/dist/index.cjs.js +136 -57
  2. package/package.json +5 -5
package/dist/index.cjs.js CHANGED
@@ -1244,7 +1244,7 @@ function setHistoryMode(mode) {
1244
1244
  }
1245
1245
  }
1246
1246
 
1247
- function parsePath() {
1247
+ function prependBasename() {
1248
1248
  var url = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
1249
1249
  return basename.replace(/\/$/, '') + '/' + url.replace(/^\//, '');
1250
1250
  }
@@ -1286,21 +1286,44 @@ var throttle = function throttle(fn, threshold) {
1286
1286
  };
1287
1287
  };
1288
1288
 
1289
- function processNavigateUrl(option) {
1290
- var url = option.url;
1291
- var matches = option.url.match(/[?&?].*/);
1292
- var parameters = '';
1289
+ var stripBasename = function stripBasename(path, basename) {
1290
+ return path.startsWith(basename) ? path.replace(basename, '') : path;
1291
+ };
1293
1292
 
1294
- if (matches && matches.length) {
1295
- parameters = matches[0];
1296
- url = url.replace(parameters, '');
1297
- }
1293
+ var isTabBar = function isTabBar(config) {
1294
+ var _a, _b;
1295
+
1296
+ var _config$router = config.router,
1297
+ _config$router$custom = _config$router.customRoutes,
1298
+ customRoutes = _config$router$custom === void 0 ? {} : _config$router$custom,
1299
+ _config$router$basena = _config$router.basename,
1300
+ basename = _config$router$basena === void 0 ? '' : _config$router$basena,
1301
+ pathname = _config$router.pathname;
1302
+ var routePath = stripBasename(pathname, basename);
1303
+ var pagePath = ((_a = Object.entries(customRoutes).find(function (_ref) {
1304
+ var _ref2 = _slicedToArray(_ref, 2),
1305
+ target = _ref2[1];
1306
+
1307
+ return target === routePath;
1308
+ })) === null || _a === void 0 ? void 0 : _a[0]) || routePath;
1309
+ return !!pagePath && (((_b = config.tabBar) === null || _b === void 0 ? void 0 : _b.list) || []).some(function (t) {
1310
+ return t.pagePath === pagePath;
1311
+ });
1312
+ };
1313
+
1314
+ function processNavigateUrl(option) {
1315
+ var pathPieces = J(option.url); // 处理自定义路由
1298
1316
 
1299
1317
  Object.keys(routesAlias).forEach(function (key) {
1300
- if (addLeadingSlash(key) === addLeadingSlash(url)) {
1301
- option.url = routesAlias[key] + parameters;
1318
+ if (addLeadingSlash(key) === addLeadingSlash(pathPieces.pathname)) {
1319
+ pathPieces.pathname = routesAlias[key];
1302
1320
  }
1303
- });
1321
+ }); // 处理 basename
1322
+
1323
+ pathPieces.pathname = prependBasename(pathPieces.pathname); // hack fix history v5 bug: https://github.com/remix-run/history/issues/814
1324
+
1325
+ if (!pathPieces.search) pathPieces.search = '';
1326
+ return pathPieces;
1304
1327
  }
1305
1328
 
1306
1329
  function navigate(option, method) {
@@ -1309,19 +1332,18 @@ function navigate(option, method) {
1309
1332
  fail = option.fail;
1310
1333
  var failReason;
1311
1334
 
1312
- if (option.url) {
1313
- processNavigateUrl(option);
1314
- }
1315
-
1316
1335
  try {
1317
- if (method === 'navigateTo') {
1318
- exports.history.push(parsePath(option.url), {
1336
+ if ('url' in option) {
1337
+ var pathPieces = processNavigateUrl(option);
1338
+ var state = {
1319
1339
  timestamp: Date.now()
1320
- });
1321
- } else if (method === 'redirectTo') {
1322
- exports.history.replace(parsePath(option.url), {
1323
- timestamp: Date.now()
1324
- });
1340
+ };
1341
+
1342
+ if (method === 'navigateTo') {
1343
+ exports.history.push(pathPieces, state);
1344
+ } else if (method === 'redirectTo') {
1345
+ exports.history.replace(pathPieces, state);
1346
+ }
1325
1347
  } else if (method === 'navigateBack') {
1326
1348
  setHistoryBackDelta(option.delta);
1327
1349
  exports.history.go(-option.delta);
@@ -1368,10 +1390,12 @@ function navigateBack() {
1368
1390
  }
1369
1391
 
1370
1392
  function switchTab(option) {
1371
- return navigateTo(option);
1393
+ // TODO: 清除掉所有的栈去目标页面
1394
+ return redirectTo(option);
1372
1395
  }
1373
1396
 
1374
1397
  function reLaunch(option) {
1398
+ // TODO: 清除掉所有的栈去目标页面
1375
1399
  return redirectTo(option);
1376
1400
  }
1377
1401
 
@@ -2043,6 +2067,10 @@ function initTabbar(config) {
2043
2067
  tabbar.conf.customRoutes = {};
2044
2068
  }
2045
2069
 
2070
+ if (typeof routerConfig.basename !== 'undefined') {
2071
+ tabbar.conf.basename = routerConfig.basename;
2072
+ }
2073
+
2046
2074
  var container = document.getElementById('container'); // eslint-disable-next-line no-unused-expressions
2047
2075
 
2048
2076
  container === null || container === void 0 ? void 0 : container.appendChild(tabbar);
@@ -2812,14 +2840,14 @@ function createRouter(app, config, framework) {
2812
2840
  });
2813
2841
  app.onLaunch();
2814
2842
  var render = throttle( /*#__PURE__*/function () {
2815
- var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(_ref) {
2816
- var location, action, _a, _b, _c, _d, element, pageConfig, enablePullDownRefresh, shouldLoad, delta, prevIndex, prev, el, _config, pathname, page;
2843
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(_ref3) {
2844
+ var location, action, _a, _b, _c, _d, element, pageConfig, enablePullDownRefresh, shouldLoad, delta, prevIndex, prev, pathname, _prevIndex, _prev, el, loadConfig, _pathname, routerIndex, page;
2817
2845
 
2818
2846
  return regeneratorRuntime.wrap(function _callee$(_context) {
2819
2847
  while (1) {
2820
2848
  switch (_context.prev = _context.next) {
2821
2849
  case 0:
2822
- location = _ref.location, action = _ref.action;
2850
+ location = _ref3.location, action = _ref3.action;
2823
2851
  routerConfig.router.pathname = location.pathname;
2824
2852
  _context.prev = 2;
2825
2853
  _context.next = 5;
@@ -2875,45 +2903,96 @@ function createRouter(app, config, framework) {
2875
2903
 
2876
2904
  shouldLoad = false;
2877
2905
 
2878
- if (action === 'POP') {
2879
- unloadPage(runtime.Current.page);
2880
- delta = historyBackDelta;
2906
+ if (!(action === 'POP')) {
2907
+ _context.next = 32;
2908
+ break;
2909
+ }
2881
2910
 
2882
- while (delta-- > 1) {
2883
- unloadPage(stacks.slice(-1)[0]);
2884
- } // 最终必须重置为 1
2911
+ unloadPage(runtime.Current.page);
2912
+ delta = historyBackDelta;
2885
2913
 
2914
+ while (delta-- > 1) {
2915
+ unloadPage(stacks.slice(-1)[0]);
2916
+ } // 最终必须重置为 1
2886
2917
 
2887
- setHistoryBackDelta(1);
2888
- prevIndex = stacks.reduceRight(function (p, s, i) {
2889
- if (p !== 0) return p;else if (s.path === location.pathname + runtime.stringify(qs(i))) return i;else return 0;
2890
- }, 0);
2891
- prev = stacks[prevIndex];
2892
2918
 
2893
- if (prev) {
2894
- showPage(prev, pageConfig, prevIndex);
2895
- } else {
2896
- shouldLoad = true;
2897
- }
2898
- } else if (action === 'PUSH') {
2899
- hidePage(runtime.Current.page);
2900
- shouldLoad = true;
2901
- } else if (action === 'REPLACE') {
2902
- unloadPage(runtime.Current.page);
2919
+ setHistoryBackDelta(1);
2920
+ prevIndex = stacks.reduceRight(function (p, s, i) {
2921
+ if (p !== 0) return p;else if (s.path === location.pathname + runtime.stringify(qs(i))) return i;else return 0;
2922
+ }, 0);
2923
+ prev = stacks[prevIndex];
2924
+
2925
+ if (prev) {
2926
+ showPage(prev, pageConfig, prevIndex);
2927
+ } else {
2903
2928
  shouldLoad = true;
2904
2929
  }
2905
2930
 
2931
+ _context.next = 49;
2932
+ break;
2933
+
2934
+ case 32:
2935
+ if (!(action === 'PUSH')) {
2936
+ _context.next = 37;
2937
+ break;
2938
+ }
2939
+
2940
+ hidePage(runtime.Current.page);
2941
+ shouldLoad = true;
2942
+ _context.next = 49;
2943
+ break;
2944
+
2945
+ case 37:
2946
+ if (!(action === 'REPLACE')) {
2947
+ _context.next = 49;
2948
+ break;
2949
+ }
2950
+
2951
+ if (!isTabBar(config)) {
2952
+ _context.next = 47;
2953
+ break;
2954
+ }
2955
+
2956
+ hidePage(runtime.Current.page);
2957
+ pathname = stripBasename(config.router.pathname, basename);
2958
+ _prevIndex = stacks.findIndex(function (r) {
2959
+ var _a;
2960
+
2961
+ return ((_a = r.path) === null || _a === void 0 ? void 0 : _a.replace(/\?.*/g, '')) === pathname;
2962
+ });
2963
+
2964
+ if (!(_prevIndex > -1)) {
2965
+ _context.next = 45;
2966
+ break;
2967
+ }
2968
+
2969
+ // tabbar 页且之前出现过,直接复用
2970
+ _prev = stacks[_prevIndex];
2971
+ return _context.abrupt("return", showPage(_prev, pageConfig, _prevIndex));
2972
+
2973
+ case 45:
2974
+ _context.next = 48;
2975
+ break;
2976
+
2977
+ case 47:
2978
+ unloadPage(runtime.Current.page);
2979
+
2980
+ case 48:
2981
+ shouldLoad = true;
2982
+
2983
+ case 49:
2906
2984
  if (shouldLoad) {
2907
2985
  el = (_c = element["default"]) !== null && _c !== void 0 ? _c : element;
2908
- _config = Object.assign({}, pageConfig);
2909
- delete _config['path'];
2910
- delete _config['load'];
2911
- pathname = basename ? location.pathname.replace(basename, '') : location.pathname;
2912
- page = runtime.createPageConfig(enablePullDownRefresh ? (_d = runtimeHooks.createPullDownComponent) === null || _d === void 0 ? void 0 : _d.call(runtimeHooks, el, location.pathname, framework, routerConfig.PullDownRefresh) : el, pathname + runtime.stringify(qs(stacks.length)), {}, _config);
2913
- loadPage(page, pageConfig, stacks.length);
2986
+ loadConfig = Object.assign({}, pageConfig);
2987
+ delete loadConfig['path'];
2988
+ delete loadConfig['load'];
2989
+ _pathname = stripBasename(config.router.pathname, basename);
2990
+ routerIndex = stacks.length;
2991
+ page = runtime.createPageConfig(enablePullDownRefresh ? (_d = runtimeHooks.createPullDownComponent) === null || _d === void 0 ? void 0 : _d.call(runtimeHooks, el, location.pathname, framework, routerConfig.PullDownRefresh) : el, _pathname + runtime.stringify(qs(routerIndex)), {}, loadConfig);
2992
+ loadPage(page, pageConfig, routerIndex);
2914
2993
  }
2915
2994
 
2916
- case 24:
2995
+ case 50:
2917
2996
  case "end":
2918
2997
  return _context.stop();
2919
2998
  }
@@ -2922,12 +3001,12 @@ function createRouter(app, config, framework) {
2922
3001
  }));
2923
3002
 
2924
3003
  return function (_x) {
2925
- return _ref2.apply(this, arguments);
3004
+ return _ref4.apply(this, arguments);
2926
3005
  };
2927
3006
  }(), 500);
2928
3007
 
2929
3008
  if (exports.history.location.pathname === '/') {
2930
- exports.history.replace(parsePath(routes[0].path + exports.history.location.search));
3009
+ exports.history.replace(prependBasename(routes[0].path + exports.history.location.search));
2931
3010
  }
2932
3011
 
2933
3012
  render({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tarojs/taro-h5",
3
- "version": "3.3.8",
3
+ "version": "3.3.12",
4
4
  "description": "Taro h5 framework",
5
5
  "main:h5": "src/index.js",
6
6
  "main": "dist/index.cjs.js",
@@ -33,9 +33,9 @@
33
33
  "author": "O2Team",
34
34
  "license": "MIT",
35
35
  "dependencies": {
36
- "@tarojs/api": "3.3.8",
37
- "@tarojs/router": "3.3.8",
38
- "@tarojs/runtime": "3.3.8",
36
+ "@tarojs/api": "3.3.12",
37
+ "@tarojs/router": "3.3.12",
38
+ "@tarojs/runtime": "3.3.12",
39
39
  "base64-js": "^1.3.0",
40
40
  "jsonp-retry": "^1.0.3",
41
41
  "mobile-detect": "^1.4.2",
@@ -45,5 +45,5 @@
45
45
  "devDependencies": {
46
46
  "jest-fetch-mock": "^3.0.3"
47
47
  },
48
- "gitHead": "51a672907177558f20d664e7c196fdb0bff41c75"
48
+ "gitHead": "0d7650ee4263efafacd87b9c8b69bb29b2a852c0"
49
49
  }