@tarojs/router 4.0.1 → 4.0.2

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/README.md CHANGED
@@ -20,7 +20,7 @@ H5 端路由系统。
20
20
 
21
21
  #### `type`
22
22
 
23
- 框架类型,`react` | `vue` | `nerv` 三选一。
23
+ 框架类型,`react` | `vue` | `solid` | `preact` 四选一。
24
24
 
25
25
  #### `framework`
26
26
 
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[];
@@ -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
@@ -225,7 +225,7 @@ function initNavigationBar(config, container) {
225
225
  }
226
226
 
227
227
  function initTabbar(config, history) {
228
- if (config.tabBar == null) {
228
+ if (config.tabBar == null || config.tabBar.custom) {
229
229
  return;
230
230
  }
231
231
  // TODO: custom-tab-bar
@@ -794,6 +794,7 @@ class MultiPageHandler {
794
794
  this.onReady(page, true);
795
795
  (_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
796
796
  this.bindPageEvents(page, pageConfig);
797
+ this.triggerRouterChange();
797
798
  });
798
799
  }
799
800
  getPageContainer(page) {
@@ -821,6 +822,19 @@ class MultiPageHandler {
821
822
  bindPageScroll(page, scrollEl, distance);
822
823
  bindPageResize(page);
823
824
  }
825
+ triggerRouterChange() {
826
+ /**
827
+ * @tarojs/runtime 中生命周期跑在 promise 中,所以这里需要 setTimeout 延迟事件调用
828
+ * TODO 考虑将生命周期返回 Promise,用于处理相关事件调用顺序
829
+ */
830
+ setTimeout(() => {
831
+ runtime.eventCenter.trigger('__afterTaroRouterChange', {
832
+ toLocation: {
833
+ path: this.pathname
834
+ }
835
+ });
836
+ }, 0);
837
+ }
824
838
  }
825
839
 
826
840
  const createStampId$1 = runtime.incrementId();
@@ -834,8 +848,8 @@ const launchStampId$1 = createStampId$1();
834
848
  * - 不支持路由动画
835
849
  */
836
850
  function createMultiRouter(history, app, config, framework) {
837
- var _a, _b, _c, _d, _e, _f;
838
851
  return tslib.__awaiter(this, void 0, void 0, function* () {
852
+ var _a, _b, _c, _d, _e, _f;
839
853
  if (typeof app.onUnhandledRejection === 'function') {
840
854
  window.addEventListener('unhandledrejection', app.onUnhandledRejection);
841
855
  }
@@ -843,7 +857,7 @@ function createMultiRouter(history, app, config, framework) {
843
857
  RouterConfig.config = config;
844
858
  const handler = new MultiPageHandler(config, history);
845
859
  const launchParam = {
846
- path: config.pageName,
860
+ path: config.pageName, // 多页面模式没新开一个页面相当于重启,所以直接使用当前页面路径
847
861
  query: handler.getQuery(launchStampId$1),
848
862
  scene: 0,
849
863
  shareTicket: '',
@@ -1510,11 +1524,11 @@ function createRouter(history$1, app, config, framework) {
1510
1524
  runtime.eventCenter.trigger('__taroRouterLaunch', launchParam);
1511
1525
  (_a = app.onLaunch) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
1512
1526
  app.onError && window.addEventListener('error', e => { var _a; return (_a = app.onError) === null || _a === void 0 ? void 0 : _a.call(app, e.message); });
1513
- const render = ({ location, action }) => tslib.__awaiter(this, void 0, void 0, function* () {
1514
- var _c, _d, _e, _f, _g, _h, _j, _k;
1527
+ const render = (_c) => tslib.__awaiter(this, [_c], void 0, function* ({ location, action }) {
1528
+ var _d, _e, _f, _g, _h, _j, _k, _l;
1515
1529
  // Note: 由于下面有异步加载操作 先不要在这里去设置 handler.pathname
1516
1530
  const currentPathname = decodeURI(location.pathname);
1517
- if ((_c = window.__taroAppConfig) === null || _c === void 0 ? void 0 : _c.usingWindowScroll)
1531
+ if ((_d = window.__taroAppConfig) === null || _d === void 0 ? void 0 : _d.usingWindowScroll)
1518
1532
  window.scrollTo(0, 0);
1519
1533
  runtime.eventCenter.trigger('__taroRouterChange', {
1520
1534
  toLocation: {
@@ -1538,7 +1552,7 @@ function createRouter(history$1, app, config, framework) {
1538
1552
  path: currentPathname,
1539
1553
  query: handler.getQuery(createStampId()),
1540
1554
  };
1541
- (_d = app.onPageNotFound) === null || _d === void 0 ? void 0 : _d.call(app, notFoundEvent);
1555
+ (_e = app.onPageNotFound) === null || _e === void 0 ? void 0 : _e.call(app, notFoundEvent);
1542
1556
  runtime.eventCenter.trigger('__taroRouterNotFound', notFoundEvent);
1543
1557
  }
1544
1558
  else if (/Loading hot update .* failed./.test(error.message)) {
@@ -1555,10 +1569,10 @@ function createRouter(history$1, app, config, framework) {
1555
1569
  // context.pathname 在 universal-router 被处理过了,是发起资源请求的时候传入的 pathname,即 await router.resolve(routerPath) 这个 routerPath
1556
1570
  handler.pathname = context.pathname;
1557
1571
  const { pathname, pageConfig } = handler;
1558
- let enablePullDownRefresh = ((_e = config === null || config === void 0 ? void 0 : config.window) === null || _e === void 0 ? void 0 : _e.enablePullDownRefresh) || false;
1559
- let navigationStyle = ((_f = config === null || config === void 0 ? void 0 : config.window) === null || _f === void 0 ? void 0 : _f.navigationStyle) || 'default';
1560
- let navigationBarTextStyle = ((_g = config === null || config === void 0 ? void 0 : config.window) === null || _g === void 0 ? void 0 : _g.navigationBarTextStyle) || 'white';
1561
- let navigationBarBackgroundColor = ((_h = config === null || config === void 0 ? void 0 : config.window) === null || _h === void 0 ? void 0 : _h.navigationBarBackgroundColor) || '#000000';
1572
+ let enablePullDownRefresh = ((_f = config === null || config === void 0 ? void 0 : config.window) === null || _f === void 0 ? void 0 : _f.enablePullDownRefresh) || false;
1573
+ let navigationStyle = ((_g = config === null || config === void 0 ? void 0 : config.window) === null || _g === void 0 ? void 0 : _g.navigationStyle) || 'default';
1574
+ let navigationBarTextStyle = ((_h = config === null || config === void 0 ? void 0 : config.window) === null || _h === void 0 ? void 0 : _h.navigationBarTextStyle) || 'white';
1575
+ let navigationBarBackgroundColor = ((_j = config === null || config === void 0 ? void 0 : config.window) === null || _j === void 0 ? void 0 : _j.navigationBarBackgroundColor) || '#000000';
1562
1576
  if (pageConfig) {
1563
1577
  if (typeof pageConfig.enablePullDownRefresh === 'boolean') {
1564
1578
  enablePullDownRefresh = pageConfig.enablePullDownRefresh;
@@ -1575,7 +1589,7 @@ function createRouter(history$1, app, config, framework) {
1575
1589
  }
1576
1590
  runtime.eventCenter.trigger('__taroSetNavigationStyle', navigationStyle, navigationBarTextStyle, navigationBarBackgroundColor);
1577
1591
  const currentPage = runtime.Current.page;
1578
- const methodName = (_j = stacks.method) !== null && _j !== void 0 ? _j : '';
1592
+ const methodName = (_k = stacks.method) !== null && _k !== void 0 ? _k : '';
1579
1593
  const cacheTabs = stacks.getTabs();
1580
1594
  let shouldLoad = false;
1581
1595
  stacks.method = '';
@@ -1642,7 +1656,7 @@ function createRouter(history$1, app, config, framework) {
1642
1656
  shouldLoad = true;
1643
1657
  }
1644
1658
  if (shouldLoad || stacks.length < 1) {
1645
- const el = (_k = element.default) !== null && _k !== void 0 ? _k : element;
1659
+ const el = (_l = element.default) !== null && _l !== void 0 ? _l : element;
1646
1660
  const loadConfig = Object.assign({}, pageConfig);
1647
1661
  const stacksIndex = stacks.length;
1648
1662
  delete loadConfig['path'];
@@ -1698,7 +1712,7 @@ function handleAppMount(config, _, appId = config.appId || 'app') {
1698
1712
  app.id = appId;
1699
1713
  isPosition = false;
1700
1714
  }
1701
- const appWrapper = (app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body;
1715
+ const appWrapper = ((app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body);
1702
1716
  app.classList.add('taro_router');
1703
1717
  if (!isPosition)
1704
1718
  appWrapper.appendChild(app);
@@ -1712,7 +1726,7 @@ function handleAppMountWithTabbar(config, history, appId = config.appId || 'app'
1712
1726
  app.id = appId;
1713
1727
  isPosition = false;
1714
1728
  }
1715
- const appWrapper = (app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body;
1729
+ const appWrapper = ((app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body);
1716
1730
  app.classList.add('taro_router');
1717
1731
  const container = document.createElement('div');
1718
1732
  container.classList.add('taro-tabbar__container');
@@ -1731,11 +1745,11 @@ function handleAppMountWithTabbar(config, history, appId = config.appId || 'app'
1731
1745
  initNavigationBar(config, container);
1732
1746
  }
1733
1747
 
1734
- Object.defineProperty(exports, 'createBrowserHistory', {
1748
+ Object.defineProperty(exports, "createBrowserHistory", {
1735
1749
  enumerable: true,
1736
1750
  get: function () { return history.createBrowserHistory; }
1737
1751
  });
1738
- Object.defineProperty(exports, 'createHashHistory', {
1752
+ Object.defineProperty(exports, "createHashHistory", {
1739
1753
  enumerable: true,
1740
1754
  get: function () { return history.createHashHistory; }
1741
1755
  });
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;
package/dist/index.esm.js CHANGED
@@ -224,7 +224,7 @@ function initNavigationBar(config, container) {
224
224
  }
225
225
 
226
226
  function initTabbar(config, history) {
227
- if (config.tabBar == null) {
227
+ if (config.tabBar == null || config.tabBar.custom) {
228
228
  return;
229
229
  }
230
230
  // TODO: custom-tab-bar
@@ -793,6 +793,7 @@ class MultiPageHandler {
793
793
  this.onReady(page, true);
794
794
  (_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
795
795
  this.bindPageEvents(page, pageConfig);
796
+ this.triggerRouterChange();
796
797
  });
797
798
  }
798
799
  getPageContainer(page) {
@@ -820,6 +821,19 @@ class MultiPageHandler {
820
821
  bindPageScroll(page, scrollEl, distance);
821
822
  bindPageResize(page);
822
823
  }
824
+ triggerRouterChange() {
825
+ /**
826
+ * @tarojs/runtime 中生命周期跑在 promise 中,所以这里需要 setTimeout 延迟事件调用
827
+ * TODO 考虑将生命周期返回 Promise,用于处理相关事件调用顺序
828
+ */
829
+ setTimeout(() => {
830
+ eventCenter.trigger('__afterTaroRouterChange', {
831
+ toLocation: {
832
+ path: this.pathname
833
+ }
834
+ });
835
+ }, 0);
836
+ }
823
837
  }
824
838
 
825
839
  const createStampId$1 = incrementId();
@@ -833,8 +847,8 @@ const launchStampId$1 = createStampId$1();
833
847
  * - 不支持路由动画
834
848
  */
835
849
  function createMultiRouter(history, app, config, framework) {
836
- var _a, _b, _c, _d, _e, _f;
837
850
  return __awaiter(this, void 0, void 0, function* () {
851
+ var _a, _b, _c, _d, _e, _f;
838
852
  if (typeof app.onUnhandledRejection === 'function') {
839
853
  window.addEventListener('unhandledrejection', app.onUnhandledRejection);
840
854
  }
@@ -842,7 +856,7 @@ function createMultiRouter(history, app, config, framework) {
842
856
  RouterConfig.config = config;
843
857
  const handler = new MultiPageHandler(config, history);
844
858
  const launchParam = {
845
- path: config.pageName,
859
+ path: config.pageName, // 多页面模式没新开一个页面相当于重启,所以直接使用当前页面路径
846
860
  query: handler.getQuery(launchStampId$1),
847
861
  scene: 0,
848
862
  shareTicket: '',
@@ -1509,11 +1523,11 @@ function createRouter(history, app, config, framework) {
1509
1523
  eventCenter.trigger('__taroRouterLaunch', launchParam);
1510
1524
  (_a = app.onLaunch) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
1511
1525
  app.onError && window.addEventListener('error', e => { var _a; return (_a = app.onError) === null || _a === void 0 ? void 0 : _a.call(app, e.message); });
1512
- const render = ({ location, action }) => __awaiter(this, void 0, void 0, function* () {
1513
- var _c, _d, _e, _f, _g, _h, _j, _k;
1526
+ const render = (_c) => __awaiter(this, [_c], void 0, function* ({ location, action }) {
1527
+ var _d, _e, _f, _g, _h, _j, _k, _l;
1514
1528
  // Note: 由于下面有异步加载操作 先不要在这里去设置 handler.pathname
1515
1529
  const currentPathname = decodeURI(location.pathname);
1516
- if ((_c = window.__taroAppConfig) === null || _c === void 0 ? void 0 : _c.usingWindowScroll)
1530
+ if ((_d = window.__taroAppConfig) === null || _d === void 0 ? void 0 : _d.usingWindowScroll)
1517
1531
  window.scrollTo(0, 0);
1518
1532
  eventCenter.trigger('__taroRouterChange', {
1519
1533
  toLocation: {
@@ -1537,7 +1551,7 @@ function createRouter(history, app, config, framework) {
1537
1551
  path: currentPathname,
1538
1552
  query: handler.getQuery(createStampId()),
1539
1553
  };
1540
- (_d = app.onPageNotFound) === null || _d === void 0 ? void 0 : _d.call(app, notFoundEvent);
1554
+ (_e = app.onPageNotFound) === null || _e === void 0 ? void 0 : _e.call(app, notFoundEvent);
1541
1555
  eventCenter.trigger('__taroRouterNotFound', notFoundEvent);
1542
1556
  }
1543
1557
  else if (/Loading hot update .* failed./.test(error.message)) {
@@ -1554,10 +1568,10 @@ function createRouter(history, app, config, framework) {
1554
1568
  // context.pathname 在 universal-router 被处理过了,是发起资源请求的时候传入的 pathname,即 await router.resolve(routerPath) 这个 routerPath
1555
1569
  handler.pathname = context.pathname;
1556
1570
  const { pathname, pageConfig } = handler;
1557
- let enablePullDownRefresh = ((_e = config === null || config === void 0 ? void 0 : config.window) === null || _e === void 0 ? void 0 : _e.enablePullDownRefresh) || false;
1558
- let navigationStyle = ((_f = config === null || config === void 0 ? void 0 : config.window) === null || _f === void 0 ? void 0 : _f.navigationStyle) || 'default';
1559
- let navigationBarTextStyle = ((_g = config === null || config === void 0 ? void 0 : config.window) === null || _g === void 0 ? void 0 : _g.navigationBarTextStyle) || 'white';
1560
- let navigationBarBackgroundColor = ((_h = config === null || config === void 0 ? void 0 : config.window) === null || _h === void 0 ? void 0 : _h.navigationBarBackgroundColor) || '#000000';
1571
+ let enablePullDownRefresh = ((_f = config === null || config === void 0 ? void 0 : config.window) === null || _f === void 0 ? void 0 : _f.enablePullDownRefresh) || false;
1572
+ let navigationStyle = ((_g = config === null || config === void 0 ? void 0 : config.window) === null || _g === void 0 ? void 0 : _g.navigationStyle) || 'default';
1573
+ let navigationBarTextStyle = ((_h = config === null || config === void 0 ? void 0 : config.window) === null || _h === void 0 ? void 0 : _h.navigationBarTextStyle) || 'white';
1574
+ let navigationBarBackgroundColor = ((_j = config === null || config === void 0 ? void 0 : config.window) === null || _j === void 0 ? void 0 : _j.navigationBarBackgroundColor) || '#000000';
1561
1575
  if (pageConfig) {
1562
1576
  if (typeof pageConfig.enablePullDownRefresh === 'boolean') {
1563
1577
  enablePullDownRefresh = pageConfig.enablePullDownRefresh;
@@ -1574,7 +1588,7 @@ function createRouter(history, app, config, framework) {
1574
1588
  }
1575
1589
  eventCenter.trigger('__taroSetNavigationStyle', navigationStyle, navigationBarTextStyle, navigationBarBackgroundColor);
1576
1590
  const currentPage = Current.page;
1577
- const methodName = (_j = stacks.method) !== null && _j !== void 0 ? _j : '';
1591
+ const methodName = (_k = stacks.method) !== null && _k !== void 0 ? _k : '';
1578
1592
  const cacheTabs = stacks.getTabs();
1579
1593
  let shouldLoad = false;
1580
1594
  stacks.method = '';
@@ -1641,7 +1655,7 @@ function createRouter(history, app, config, framework) {
1641
1655
  shouldLoad = true;
1642
1656
  }
1643
1657
  if (shouldLoad || stacks.length < 1) {
1644
- const el = (_k = element.default) !== null && _k !== void 0 ? _k : element;
1658
+ const el = (_l = element.default) !== null && _l !== void 0 ? _l : element;
1645
1659
  const loadConfig = Object.assign({}, pageConfig);
1646
1660
  const stacksIndex = stacks.length;
1647
1661
  delete loadConfig['path'];
@@ -1697,7 +1711,7 @@ function handleAppMount(config, _, appId = config.appId || 'app') {
1697
1711
  app.id = appId;
1698
1712
  isPosition = false;
1699
1713
  }
1700
- const appWrapper = (app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body;
1714
+ const appWrapper = ((app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body);
1701
1715
  app.classList.add('taro_router');
1702
1716
  if (!isPosition)
1703
1717
  appWrapper.appendChild(app);
@@ -1711,7 +1725,7 @@ function handleAppMountWithTabbar(config, history, appId = config.appId || 'app'
1711
1725
  app.id = appId;
1712
1726
  isPosition = false;
1713
1727
  }
1714
- const appWrapper = (app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body;
1728
+ const appWrapper = ((app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body);
1715
1729
  app.classList.add('taro_router');
1716
1730
  const container = document.createElement('div');
1717
1731
  container.classList.add('taro-tabbar__container');
package/dist/index.js CHANGED
@@ -16,7 +16,7 @@ function handleAppMount(config, _, appId = config.appId || 'app') {
16
16
  app.id = appId;
17
17
  isPosition = false;
18
18
  }
19
- const appWrapper = (app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body;
19
+ const appWrapper = ((app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body);
20
20
  app.classList.add('taro_router');
21
21
  if (!isPosition)
22
22
  appWrapper.appendChild(app);
@@ -30,7 +30,7 @@ function handleAppMountWithTabbar(config, history, appId = config.appId || 'app'
30
30
  app.id = appId;
31
31
  isPosition = false;
32
32
  }
33
- const appWrapper = (app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body;
33
+ const appWrapper = ((app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body);
34
34
  app.classList.add('taro_router');
35
35
  const container = document.createElement('div');
36
36
  container.classList.add('taro-tabbar__container');
@@ -1,3 +1,2 @@
1
- import { MpaRouterConfig, SpaRouterConfig } from '../types/router';
2
- declare function initNavigationBar(config: SpaRouterConfig | MpaRouterConfig, container: HTMLElement): void;
3
- export { initNavigationBar };
1
+ import type { MpaRouterConfig, SpaRouterConfig } from '../types/router';
2
+ export declare function initNavigationBar(config: SpaRouterConfig | MpaRouterConfig, container: HTMLElement): void;
@@ -1,13 +1,11 @@
1
- import { MpaRouterConfig, SpaRouterConfig } from '../../types/router';
2
- declare class RouterConfig {
1
+ import type { MpaRouterConfig, SpaRouterConfig } from '../../types/router';
2
+ export declare class RouterConfig {
3
3
  private static __config;
4
4
  static set config(e: SpaRouterConfig | MpaRouterConfig);
5
5
  static get config(): SpaRouterConfig | MpaRouterConfig;
6
6
  static get pages(): string[];
7
- static get router(): import("../types/router").Router;
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 中
11
10
  static isPage(url?: string): boolean;
12
11
  }
13
- export { RouterConfig };
@@ -1,6 +1,6 @@
1
- import { AppInstance } from '@tarojs/runtime';
2
- import { History } from "../history.js";
3
- import { MpaRouterConfig } from '../../types/router';
1
+ import type { AppInstance } from '@tarojs/runtime';
2
+ import type { History } from 'history';
3
+ import type { MpaRouterConfig } from '../../types/router';
4
4
  /** Note: 关于多页面应用
5
5
  * - 需要配置路由映射(根目录跳转、404 页面……)
6
6
  * - app.onPageNotFound 事件不支持
@@ -8,5 +8,4 @@ import { MpaRouterConfig } from '../../types/router';
8
8
  * - TabBar 会多次加载
9
9
  * - 不支持路由动画
10
10
  */
11
- declare function createMultiRouter(history: History, app: AppInstance, config: MpaRouterConfig, framework?: string): Promise<void>;
12
- export { createMultiRouter };
11
+ export declare function createMultiRouter(history: History, app: AppInstance, config: MpaRouterConfig, framework?: string): Promise<void>;
@@ -16,8 +16,8 @@ const launchStampId = createStampId();
16
16
  * - 不支持路由动画
17
17
  */
18
18
  function createMultiRouter(history, app, config, framework) {
19
- var _a, _b, _c, _d, _e, _f;
20
19
  return __awaiter(this, void 0, void 0, function* () {
20
+ var _a, _b, _c, _d, _e, _f;
21
21
  if (typeof app.onUnhandledRejection === 'function') {
22
22
  window.addEventListener('unhandledrejection', app.onUnhandledRejection);
23
23
  }
@@ -25,7 +25,7 @@ function createMultiRouter(history, app, config, framework) {
25
25
  RouterConfig.config = config;
26
26
  const handler = new MultiPageHandler(config, history);
27
27
  const launchParam = {
28
- path: config.pageName,
28
+ path: config.pageName, // 多页面模式没新开一个页面相当于重启,所以直接使用当前页面路径
29
29
  query: handler.getQuery(launchStampId),
30
30
  scene: 0,
31
31
  shareTicket: '',
@@ -1,13 +1,13 @@
1
- import { PageInstance } from '@tarojs/runtime';
2
- import { PageConfig } from '@tarojs/taro';
3
- import { History } from "../history.js";
4
- import { MpaRouterConfig, Route } from '../../types/router';
5
- declare class MultiPageHandler {
1
+ import type { PageInstance } from '@tarojs/runtime';
2
+ import type { PageConfig } from '@tarojs/taro';
3
+ import type { History } from 'history';
4
+ import type { MpaRouterConfig, Route } from '../../types/router';
5
+ export default class MultiPageHandler {
6
6
  history: History;
7
7
  protected config: MpaRouterConfig;
8
8
  constructor(config: MpaRouterConfig, history: History);
9
9
  get appId(): string;
10
- get router(): import("../types/router").Router;
10
+ get router(): import("../../types/router").Router;
11
11
  get routerMode(): "hash" | "browser" | "multi";
12
12
  get customRoutes(): Record<string, string | string[]>;
13
13
  get tabBarList(): import("@tarojs/taro").TabBarItem[];
@@ -27,7 +27,7 @@ declare class MultiPageHandler {
27
27
  onReady(page: PageInstance, onLoad?: boolean): void;
28
28
  load(page: PageInstance, pageConfig?: Route): void;
29
29
  getPageContainer(page?: PageInstance | null): HTMLElement | null;
30
- getScrollingElement(page?: PageInstance | null): HTMLElement | (Window & typeof globalThis);
30
+ getScrollingElement(page?: PageInstance | null): (Window & typeof globalThis) | HTMLElement;
31
31
  bindPageEvents(page: PageInstance, config?: Partial<PageConfig>): void;
32
+ triggerRouterChange(): void;
32
33
  }
33
- export { MultiPageHandler as default };
@@ -1,4 +1,4 @@
1
- import { addLeadingSlash, stripBasename, Current } from '@tarojs/runtime';
1
+ import { addLeadingSlash, stripBasename, Current, eventCenter } from '@tarojs/runtime';
2
2
  import queryString from 'query-string';
3
3
  import { bindPageResize } from '../events/resize.js';
4
4
  import { bindPageScroll } from '../events/scroll.js';
@@ -106,6 +106,7 @@ class MultiPageHandler {
106
106
  this.onReady(page, true);
107
107
  (_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
108
108
  this.bindPageEvents(page, pageConfig);
109
+ this.triggerRouterChange();
109
110
  });
110
111
  }
111
112
  getPageContainer(page) {
@@ -133,6 +134,19 @@ class MultiPageHandler {
133
134
  bindPageScroll(page, scrollEl, distance);
134
135
  bindPageResize(page);
135
136
  }
137
+ triggerRouterChange() {
138
+ /**
139
+ * @tarojs/runtime 中生命周期跑在 promise 中,所以这里需要 setTimeout 延迟事件调用
140
+ * TODO 考虑将生命周期返回 Promise,用于处理相关事件调用顺序
141
+ */
142
+ setTimeout(() => {
143
+ eventCenter.trigger('__afterTaroRouterChange', {
144
+ toLocation: {
145
+ path: this.pathname
146
+ }
147
+ });
148
+ }, 0);
149
+ }
136
150
  }
137
151
 
138
152
  export { MultiPageHandler as default };
@@ -1,4 +1,4 @@
1
- import PageHandler from "./page.js";
1
+ import type PageHandler from './page';
2
2
  interface NavigationBarCache {
3
3
  backgroundColor?: string;
4
4
  fontColor?: string;
@@ -6,7 +6,7 @@ interface NavigationBarCache {
6
6
  show?: boolean;
7
7
  loading?: boolean;
8
8
  }
9
- declare class NavigationBarHandler {
9
+ export default class NavigationBarHandler {
10
10
  pageContext: PageHandler;
11
11
  navigationBarElement: HTMLElement;
12
12
  cache: Record<string, NavigationBarCache>;
@@ -33,4 +33,4 @@ declare class NavigationBarHandler {
33
33
  fnBtnToggleToNone(): void;
34
34
  setNavigationBarVisible(show?: any): void;
35
35
  }
36
- export { NavigationBarHandler as default };
36
+ export {};
@@ -1,9 +1,9 @@
1
- import NavigationBarHandler from "./navigation-bar.js";
2
- import { PageInstance } from '@tarojs/runtime';
3
- import { PageConfig, RouterAnimate } from '@tarojs/taro';
4
- import { History } from "../history.js";
5
- import { Route, SpaRouterConfig } from '../../types/router';
6
- declare class PageHandler {
1
+ import NavigationBarHandler from './navigation-bar';
2
+ import type { PageInstance } from '@tarojs/runtime';
3
+ import type { PageConfig, RouterAnimate } from '@tarojs/taro';
4
+ import type { History } from 'history';
5
+ import type { Route, SpaRouterConfig } from '../../types/router';
6
+ export default class PageHandler {
7
7
  history: History;
8
8
  config: SpaRouterConfig;
9
9
  protected readonly defaultAnimation: RouterAnimate;
@@ -17,7 +17,7 @@ declare class PageHandler {
17
17
  constructor(config: SpaRouterConfig, history: History);
18
18
  get currentPage(): string;
19
19
  get appId(): string;
20
- get router(): import("../types/router").Router;
20
+ get router(): import("../../types/router").Router;
21
21
  get routerMode(): "hash" | "browser" | "multi";
22
22
  get customRoutes(): Record<string, string | string[]>;
23
23
  get routes(): Route[];
@@ -47,8 +47,7 @@ declare class PageHandler {
47
47
  hide(page?: PageInstance | null, animation?: boolean): void;
48
48
  addAnimation(pageEl?: HTMLElement | null, first?: boolean): void;
49
49
  getPageContainer(page?: PageInstance | null): HTMLElement | null;
50
- getScrollingElement(page?: PageInstance | null): HTMLElement | (Window & typeof globalThis);
50
+ getScrollingElement(page?: PageInstance | null): (Window & typeof globalThis) | HTMLElement;
51
51
  bindPageEvents(page: PageInstance, config?: Partial<PageConfig>): void;
52
52
  triggerRouterChange(): void;
53
53
  }
54
- export { PageHandler as default };
@@ -1,5 +1,4 @@
1
- import { AppInstance } from '@tarojs/runtime';
2
- import { History } from "../history.js";
3
- import { SpaRouterConfig } from '../../types/router';
4
- declare function createRouter(history: History, app: AppInstance, config: SpaRouterConfig, framework?: string): () => void;
5
- export { createRouter };
1
+ import type { AppInstance } from '@tarojs/runtime';
2
+ import type { History } from 'history';
3
+ import type { SpaRouterConfig } from '../../types/router';
4
+ export declare function createRouter(history: History, app: AppInstance, config: SpaRouterConfig, framework?: string): () => void;
@@ -42,11 +42,11 @@ function createRouter(history, app, config, framework) {
42
42
  eventCenter.trigger('__taroRouterLaunch', launchParam);
43
43
  (_a = app.onLaunch) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
44
44
  app.onError && window.addEventListener('error', e => { var _a; return (_a = app.onError) === null || _a === void 0 ? void 0 : _a.call(app, e.message); });
45
- const render = ({ location, action }) => __awaiter(this, void 0, void 0, function* () {
46
- var _c, _d, _e, _f, _g, _h, _j, _k;
45
+ const render = (_c) => __awaiter(this, [_c], void 0, function* ({ location, action }) {
46
+ var _d, _e, _f, _g, _h, _j, _k, _l;
47
47
  // Note: 由于下面有异步加载操作 先不要在这里去设置 handler.pathname
48
48
  const currentPathname = decodeURI(location.pathname);
49
- if ((_c = window.__taroAppConfig) === null || _c === void 0 ? void 0 : _c.usingWindowScroll)
49
+ if ((_d = window.__taroAppConfig) === null || _d === void 0 ? void 0 : _d.usingWindowScroll)
50
50
  window.scrollTo(0, 0);
51
51
  eventCenter.trigger('__taroRouterChange', {
52
52
  toLocation: {
@@ -70,7 +70,7 @@ function createRouter(history, app, config, framework) {
70
70
  path: currentPathname,
71
71
  query: handler.getQuery(createStampId()),
72
72
  };
73
- (_d = app.onPageNotFound) === null || _d === void 0 ? void 0 : _d.call(app, notFoundEvent);
73
+ (_e = app.onPageNotFound) === null || _e === void 0 ? void 0 : _e.call(app, notFoundEvent);
74
74
  eventCenter.trigger('__taroRouterNotFound', notFoundEvent);
75
75
  }
76
76
  else if (/Loading hot update .* failed./.test(error.message)) {
@@ -87,10 +87,10 @@ function createRouter(history, app, config, framework) {
87
87
  // context.pathname 在 universal-router 被处理过了,是发起资源请求的时候传入的 pathname,即 await router.resolve(routerPath) 这个 routerPath
88
88
  handler.pathname = context.pathname;
89
89
  const { pathname, pageConfig } = handler;
90
- let enablePullDownRefresh = ((_e = config === null || config === void 0 ? void 0 : config.window) === null || _e === void 0 ? void 0 : _e.enablePullDownRefresh) || false;
91
- let navigationStyle = ((_f = config === null || config === void 0 ? void 0 : config.window) === null || _f === void 0 ? void 0 : _f.navigationStyle) || 'default';
92
- let navigationBarTextStyle = ((_g = config === null || config === void 0 ? void 0 : config.window) === null || _g === void 0 ? void 0 : _g.navigationBarTextStyle) || 'white';
93
- let navigationBarBackgroundColor = ((_h = config === null || config === void 0 ? void 0 : config.window) === null || _h === void 0 ? void 0 : _h.navigationBarBackgroundColor) || '#000000';
90
+ let enablePullDownRefresh = ((_f = config === null || config === void 0 ? void 0 : config.window) === null || _f === void 0 ? void 0 : _f.enablePullDownRefresh) || false;
91
+ let navigationStyle = ((_g = config === null || config === void 0 ? void 0 : config.window) === null || _g === void 0 ? void 0 : _g.navigationStyle) || 'default';
92
+ let navigationBarTextStyle = ((_h = config === null || config === void 0 ? void 0 : config.window) === null || _h === void 0 ? void 0 : _h.navigationBarTextStyle) || 'white';
93
+ let navigationBarBackgroundColor = ((_j = config === null || config === void 0 ? void 0 : config.window) === null || _j === void 0 ? void 0 : _j.navigationBarBackgroundColor) || '#000000';
94
94
  if (pageConfig) {
95
95
  if (typeof pageConfig.enablePullDownRefresh === 'boolean') {
96
96
  enablePullDownRefresh = pageConfig.enablePullDownRefresh;
@@ -107,7 +107,7 @@ function createRouter(history, app, config, framework) {
107
107
  }
108
108
  eventCenter.trigger('__taroSetNavigationStyle', navigationStyle, navigationBarTextStyle, navigationBarBackgroundColor);
109
109
  const currentPage = Current.page;
110
- const methodName = (_j = stacks.method) !== null && _j !== void 0 ? _j : '';
110
+ const methodName = (_k = stacks.method) !== null && _k !== void 0 ? _k : '';
111
111
  const cacheTabs = stacks.getTabs();
112
112
  let shouldLoad = false;
113
113
  stacks.method = '';
@@ -174,7 +174,7 @@ function createRouter(history, app, config, framework) {
174
174
  shouldLoad = true;
175
175
  }
176
176
  if (shouldLoad || stacks.length < 1) {
177
- const el = (_k = element.default) !== null && _k !== void 0 ? _k : element;
177
+ const el = (_l = element.default) !== null && _l !== void 0 ? _l : element;
178
178
  const loadConfig = Object.assign({}, pageConfig);
179
179
  const stacksIndex = stacks.length;
180
180
  delete loadConfig['path'];
@@ -1,4 +1,4 @@
1
- import { PageInstance } from '@tarojs/runtime';
1
+ import type { PageInstance } from '@tarojs/runtime';
2
2
  declare class Stacks {
3
3
  stacks: PageInstance[];
4
4
  backDelta: number;
@@ -23,4 +23,4 @@ declare class Stacks {
23
23
  removeTab(path: string): void;
24
24
  }
25
25
  declare const stacks: Stacks;
26
- export { stacks as default };
26
+ export default stacks;
package/dist/style.d.ts CHANGED
@@ -1,14 +1,13 @@
1
1
  /**
2
2
  * 插入页面动画需要的样式
3
3
  */
4
- declare function loadAnimateStyle(ms?: number): void;
4
+ export declare function loadAnimateStyle(ms?: number): void;
5
5
  /**
6
6
  * 插入路由相关样式
7
7
  */
8
- declare function loadRouterStyle(enableTabBar: boolean, enableWindowScroll: boolean, enhanceAnimation?: boolean): void;
8
+ export declare function loadRouterStyle(enableTabBar: boolean, enableWindowScroll: boolean, enhanceAnimation?: boolean): void;
9
9
  /**
10
10
  * 插入导航栏相关的样式
11
11
  */
12
- declare function loadNavigationBarStyle(): void;
13
- declare function addStyle(css: any): void;
14
- export { loadAnimateStyle, loadRouterStyle, loadNavigationBarStyle, addStyle };
12
+ export declare function loadNavigationBarStyle(): void;
13
+ export declare function addStyle(css: any): void;
package/dist/tabbar.d.ts CHANGED
@@ -1,4 +1,3 @@
1
1
  import { AppConfig } from '@tarojs/taro';
2
- import { History } from "./history.js";
3
- declare function initTabbar(config: AppConfig, history: History): void;
4
- export { initTabbar };
2
+ import type { History } from 'history';
3
+ export declare function initTabbar(config: AppConfig, history: History): void;
package/dist/tabbar.js CHANGED
@@ -2,7 +2,7 @@ import { defineCustomElementTaroTabbar } from '@tarojs/components/dist/component
2
2
  import { initTabBarApis } from '@tarojs/taro';
3
3
 
4
4
  function initTabbar(config, history) {
5
- if (config.tabBar == null) {
5
+ if (config.tabBar == null || config.tabBar.custom) {
6
6
  return;
7
7
  }
8
8
  // TODO: custom-tab-bar
@@ -6,6 +6,5 @@ declare class RoutesAlias {
6
6
  getAlias: (url?: string) => string;
7
7
  getAll: (url?: string) => string[];
8
8
  }
9
- declare const routesAlias: RoutesAlias;
10
- export { routesAlias };
11
- export * from "./navigate.js";
9
+ export declare const routesAlias: RoutesAlias;
10
+ export * from './navigate';
@@ -1,10 +1,9 @@
1
- declare const isWeixin: () => boolean;
2
- declare const isDingTalk: () => boolean;
3
- declare function setMpaTitle(title: string): void;
4
- declare function setTitle(title: string): void;
5
- declare function setNavigationBarStyle(option: {
1
+ export declare const isWeixin: () => boolean;
2
+ export declare const isDingTalk: () => boolean;
3
+ export declare function setMpaTitle(title: string): void;
4
+ export declare function setTitle(title: string): void;
5
+ export declare function setNavigationBarStyle(option: {
6
6
  backgroundColor: string;
7
7
  frontColor: string;
8
8
  }): void;
9
- declare function setNavigationBarLoading(loading: boolean): void;
10
- export { isWeixin, isDingTalk, setMpaTitle, setTitle, setNavigationBarStyle, setNavigationBarLoading };
9
+ export declare function setNavigationBarLoading(loading: boolean): void;
package/package.json CHANGED
@@ -1,7 +1,9 @@
1
1
  {
2
2
  "name": "@tarojs/router",
3
- "version": "4.0.1",
3
+ "version": "4.0.2",
4
4
  "description": "Taro-router",
5
+ "author": "O2Team",
6
+ "license": "MIT",
5
7
  "browser": "dist/index.js",
6
8
  "main:h5": "dist/index.esm.js",
7
9
  "main": "dist/index.js",
@@ -20,47 +22,34 @@
20
22
  "keywords": [
21
23
  "router"
22
24
  ],
23
- "author": "O2Team",
24
- "license": "MIT",
25
+ "engines": {
26
+ "node": ">= 18"
27
+ },
25
28
  "dependencies": {
26
29
  "dingtalk-jsapi": "~2.15.2",
27
- "history": "^5.1.0",
30
+ "history": "^5.3.0",
28
31
  "mobile-detect": "^1.4.2",
29
- "query-string": "^7.1.1",
32
+ "query-string": "^9.0.0",
30
33
  "tslib": "^2.6.2",
31
- "universal-router": "^8.3.0"
34
+ "universal-router": "^9.2.0"
32
35
  },
33
36
  "devDependencies": {
34
- "@rollup/plugin-commonjs": "^24.0.0",
35
- "@rollup/plugin-node-resolve": "^15.0.0",
36
- "@rollup/plugin-typescript": "^11.1.0",
37
- "@types/jest": "^29.4.0",
38
- "jest": "^29.3.1",
39
- "jest-cli": "^29.3.1",
40
- "jest-environment-jsdom": "^29.5.0",
41
- "jsdom": "^21.1.0",
42
- "rollup": "^3.8.1",
43
- "rollup-plugin-node-externals": "^5.0.0",
44
- "rollup-plugin-ts": "^3.0.2",
45
- "ts-jest": "^29.0.5",
46
- "typescript": "^4.7.4",
47
- "@tarojs/taro": "4.0.1",
48
- "@tarojs/shared": "4.0.1",
49
- "@tarojs/runtime": "4.0.1"
37
+ "@tarojs/components": "4.0.2",
38
+ "@tarojs/runtime": "4.0.2",
39
+ "@tarojs/shared": "4.0.2",
40
+ "@tarojs/taro": "4.0.2"
50
41
  },
51
42
  "peerDependencies": {
52
- "@tarojs/runtime": "4.0.1",
53
- "@tarojs/taro": "4.0.1",
54
- "@tarojs/shared": "4.0.1"
43
+ "@tarojs/taro": "4.0.2",
44
+ "@tarojs/runtime": "4.0.2",
45
+ "@tarojs/shared": "4.0.2"
55
46
  },
56
47
  "scripts": {
48
+ "prod": "pnpm run build",
57
49
  "prebuild": "pnpm run clean",
58
50
  "build": "pnpm run rollup --environment NODE_ENV:production",
59
- "clean": "rimraf ./dist",
51
+ "clean": "rimraf --impl=move-remove ./dist",
60
52
  "dev": "pnpm run rollup --environment NODE_ENV:development -w",
61
- "rollup": "rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript --bundleConfigAsCjs",
62
- "test": "cross-env NODE_ENV=jest jest",
63
- "test:ci": "cross-env NODE_ENV=jest jest --ci -i --coverage --silent",
64
- "test:dev": "cross-env NODE_ENV=jest jest --watch"
53
+ "rollup": "rollup --config rollup.config.mts --configPlugin typescript"
65
54
  }
66
55
  }
@@ -1,66 +0,0 @@
1
- import { Action, createBrowserHistory, createHashHistory, Blocker, BrowserHistoryOptions, HashHistoryOptions, History, Listener, Location, Path, To } from "history";
2
- import { IH5RouterConfig } from "@tarojs/taro/types/compile";
3
- import { StateEvent } from "../types/history";
4
- import { MpaRouterConfig, SpaRouterConfig } from '../types/router';
5
- import Taro from "@tarojs/taro";
6
- import { AppInstance } from "@tarojs/runtime";
7
- import { MpaRouterConfig as MpaRouterConfig$0 } from "../../types/router";
8
- import { SpaRouterConfig as SpaRouterConfig$0 } from "../../types/router";
9
- declare let history: History;
10
- declare class MpaHistory implements History {
11
- action: Action;
12
- get location(): Location;
13
- createHref(_to: To): string;
14
- parseUrl(to: Partial<Path>): string;
15
- push(to: Partial<Path>, _state?: Record<string, unknown>): void;
16
- replace(to: Partial<Path>, _state?: Record<string, unknown>): void;
17
- go(delta: number): void;
18
- back: () => void;
19
- forward: () => void;
20
- listen(listener: Listener): () => void;
21
- block(_blocker: Blocker): () => void;
22
- pushState: globalThis.History["pushState"];
23
- replaceState: globalThis.History["replaceState"];
24
- eventState(action: Required<StateEvent>["action"]): (data: any, unused: string, url?: string | URL | null) => any;
25
- }
26
- declare function setHistory(h: History, base?: string): void;
27
- declare function createMpaHistory(_?: HashHistoryOptions | BrowserHistoryOptions): MpaHistory;
28
- declare function setHistoryMode(mode?: IH5RouterConfig["mode"], base?: string): void;
29
- declare function prependBasename(url?: string): string;
30
- declare function navigateTo(option: Taro.navigateTo.Option): ReturnType<typeof Taro.navigateTo>;
31
- declare function redirectTo(option: Taro.redirectTo.Option): ReturnType<typeof Taro.redirectTo>;
32
- declare function navigateBack(option?: Taro.navigateBack.Option): ReturnType<typeof Taro.navigateBack>;
33
- declare function switchTab(option: Taro.switchTab.Option): ReturnType<typeof Taro.switchTab>;
34
- declare function reLaunch(option: Taro.reLaunch.Option): ReturnType<typeof Taro.reLaunch>;
35
- declare function getCurrentPages(): Taro.Page[];
36
- // TODO 支持多路由 (APP 生命周期仅触发一次)
37
- /** Note: 关于多页面应用
38
- * - 需要配置路由映射(根目录跳转、404 页面……)
39
- * - app.onPageNotFound 事件不支持
40
- * - 应用生命周期可能多次触发
41
- * - TabBar 会多次加载
42
- * - 不支持路由动画
43
- */
44
- declare function createMultiRouter(history: History, app: AppInstance, config: MpaRouterConfig$0, framework?: string): Promise<void>;
45
- declare function createRouter(history: History, app: AppInstance, config: SpaRouterConfig$0, framework?: string): () => void;
46
- declare class RoutesAlias {
47
- conf: Array<string[]>;
48
- set(customRoutes?: Record<string, string | string[]>): void;
49
- getConfig: (url?: string) => string[];
50
- getOrigin: (url?: string) => string;
51
- getAlias: (url?: string) => string;
52
- getAll: (url?: string) => string[];
53
- }
54
- declare const routesAlias: RoutesAlias;
55
- declare const isWeixin: () => boolean;
56
- declare const isDingTalk: () => boolean;
57
- declare function setMpaTitle(title: string): void;
58
- declare function setTitle(title: string): void;
59
- declare function setNavigationBarStyle(option: {
60
- backgroundColor: string;
61
- frontColor: string;
62
- }): void;
63
- declare function setNavigationBarLoading(loading: boolean): void;
64
- declare function handleAppMount(config: SpaRouterConfig | MpaRouterConfig, _: History, appId?: string): void;
65
- declare function handleAppMountWithTabbar(config: SpaRouterConfig | MpaRouterConfig, history: History, appId?: string): void;
66
- export { navigateTo, redirectTo, navigateBack, switchTab, reLaunch, getCurrentPages, history, setHistory, createMpaHistory, createBrowserHistory, createHashHistory, setHistoryMode, prependBasename, createMultiRouter, createRouter, routesAlias, isWeixin, isDingTalk, setMpaTitle, setTitle, setNavigationBarStyle, setNavigationBarLoading, handleAppMount, handleAppMountWithTabbar };
@@ -1,66 +0,0 @@
1
- import { Action, createBrowserHistory, createHashHistory, Blocker, BrowserHistoryOptions, HashHistoryOptions, History, Listener, Location, Path, To } from "history";
2
- import { IH5RouterConfig } from "@tarojs/taro/types/compile";
3
- import { StateEvent } from "../types/history";
4
- import { MpaRouterConfig, SpaRouterConfig } from '../types/router';
5
- import Taro from "@tarojs/taro";
6
- import { AppInstance } from "@tarojs/runtime";
7
- import { MpaRouterConfig as MpaRouterConfig$0 } from "../../types/router";
8
- import { SpaRouterConfig as SpaRouterConfig$0 } from "../../types/router";
9
- declare let history: History;
10
- declare class MpaHistory implements History {
11
- action: Action;
12
- get location(): Location;
13
- createHref(_to: To): string;
14
- parseUrl(to: Partial<Path>): string;
15
- push(to: Partial<Path>, _state?: Record<string, unknown>): void;
16
- replace(to: Partial<Path>, _state?: Record<string, unknown>): void;
17
- go(delta: number): void;
18
- back: () => void;
19
- forward: () => void;
20
- listen(listener: Listener): () => void;
21
- block(_blocker: Blocker): () => void;
22
- pushState: globalThis.History["pushState"];
23
- replaceState: globalThis.History["replaceState"];
24
- eventState(action: Required<StateEvent>["action"]): (data: any, unused: string, url?: string | URL | null) => any;
25
- }
26
- declare function setHistory(h: History, base?: string): void;
27
- declare function createMpaHistory(_?: HashHistoryOptions | BrowserHistoryOptions): MpaHistory;
28
- declare function setHistoryMode(mode?: IH5RouterConfig["mode"], base?: string): void;
29
- declare function prependBasename(url?: string): string;
30
- declare function navigateTo(option: Taro.navigateTo.Option): ReturnType<typeof Taro.navigateTo>;
31
- declare function redirectTo(option: Taro.redirectTo.Option): ReturnType<typeof Taro.redirectTo>;
32
- declare function navigateBack(option?: Taro.navigateBack.Option): ReturnType<typeof Taro.navigateBack>;
33
- declare function switchTab(option: Taro.switchTab.Option): ReturnType<typeof Taro.switchTab>;
34
- declare function reLaunch(option: Taro.reLaunch.Option): ReturnType<typeof Taro.reLaunch>;
35
- declare function getCurrentPages(): Taro.Page[];
36
- // TODO 支持多路由 (APP 生命周期仅触发一次)
37
- /** Note: 关于多页面应用
38
- * - 需要配置路由映射(根目录跳转、404 页面……)
39
- * - app.onPageNotFound 事件不支持
40
- * - 应用生命周期可能多次触发
41
- * - TabBar 会多次加载
42
- * - 不支持路由动画
43
- */
44
- declare function createMultiRouter(history: History, app: AppInstance, config: MpaRouterConfig$0, framework?: string): Promise<void>;
45
- declare function createRouter(history: History, app: AppInstance, config: SpaRouterConfig$0, framework?: string): () => void;
46
- declare class RoutesAlias {
47
- conf: Array<string[]>;
48
- set(customRoutes?: Record<string, string | string[]>): void;
49
- getConfig: (url?: string) => string[];
50
- getOrigin: (url?: string) => string;
51
- getAlias: (url?: string) => string;
52
- getAll: (url?: string) => string[];
53
- }
54
- declare const routesAlias: RoutesAlias;
55
- declare const isWeixin: () => boolean;
56
- declare const isDingTalk: () => boolean;
57
- declare function setMpaTitle(title: string): void;
58
- declare function setTitle(title: string): void;
59
- declare function setNavigationBarStyle(option: {
60
- backgroundColor: string;
61
- frontColor: string;
62
- }): void;
63
- declare function setNavigationBarLoading(loading: boolean): void;
64
- declare function handleAppMount(config: SpaRouterConfig | MpaRouterConfig, _: History, appId?: string): void;
65
- declare function handleAppMountWithTabbar(config: SpaRouterConfig | MpaRouterConfig, history: History, appId?: string): void;
66
- export { navigateTo, redirectTo, navigateBack, switchTab, reLaunch, getCurrentPages, history, setHistory, createMpaHistory, createBrowserHistory, createHashHistory, setHistoryMode, prependBasename, createMultiRouter, createRouter, routesAlias, isWeixin, isDingTalk, setMpaTitle, setTitle, setNavigationBarStyle, setNavigationBarLoading, handleAppMount, handleAppMountWithTabbar };