@tarojs/router 4.0.1-alpha.0 → 4.0.1

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,8 +154,15 @@ 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
+
157
164
  MIT (weui):
158
- The following files embed [weui](https://github.com/Tencent/weui) MIT:
165
+ The following files embed [stencil-vue2-output-target](https://github.com/Tencent/weui) MIT:
159
166
  `/packages/taro-components/src/components/*.scss`
160
167
  See `/LICENSE.txt` for details of the license.
161
168
 
@@ -165,10 +172,3 @@ Apache-2.0 (intersection-observer):
165
172
  The following files embed [intersection-observer](https://github.com/GoogleChromeLabs/intersection-observer) Apache-2.0:
166
173
  `/packages/taro-api/src/polyfill/intersection-observer.ts`
167
174
  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` | `solid` | `preact` 四选一。
23
+ 框架类型,`react` | `vue` | `nerv` 三选一。
24
24
 
25
25
  #### `framework`
26
26
 
package/dist/api.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import Taro from '@tarojs/taro';
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[];
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 };
@@ -1,2 +1,3 @@
1
- import type { PageInstance } from '@tarojs/runtime';
2
- export declare function bindPageResize(page: PageInstance): void;
1
+ import { PageInstance } from '@tarojs/runtime';
2
+ declare function bindPageResize(page: PageInstance): void;
3
+ export { bindPageResize };
@@ -1,2 +1,3 @@
1
- import type { PageInstance } from '@tarojs/runtime';
2
- export declare function bindPageScroll(page: PageInstance, scrollEl: HTMLElement | Window, distance?: number): void;
1
+ import { PageInstance } from '@tarojs/runtime';
2
+ declare function bindPageScroll(page: PageInstance, scrollEl: HTMLElement | Window, distance?: number): void;
3
+ export { bindPageScroll };
package/dist/history.d.ts CHANGED
@@ -1,8 +1,6 @@
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;
1
+ import { IH5RouterConfig } from '@tarojs/taro/types/compile';
2
+ import { StateEvent } from '../types/history';
3
+ declare let history: History;
6
4
  declare class MpaHistory implements History {
7
5
  action: Action;
8
6
  get location(): Location;
@@ -19,8 +17,8 @@ declare class MpaHistory implements History {
19
17
  replaceState: globalThis.History['replaceState'];
20
18
  eventState(action: Required<StateEvent>['action']): (data: any, unused: string, url?: string | URL | null) => any;
21
19
  }
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;
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 };
@@ -0,0 +1,66 @@
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 };
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 || config.tabBar.custom) {
228
+ if (config.tabBar == null) {
229
229
  return;
230
230
  }
231
231
  // TODO: custom-tab-bar
@@ -794,7 +794,6 @@ 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();
798
797
  });
799
798
  }
800
799
  getPageContainer(page) {
@@ -822,19 +821,6 @@ class MultiPageHandler {
822
821
  bindPageScroll(page, scrollEl, distance);
823
822
  bindPageResize(page);
824
823
  }
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
- }
838
824
  }
839
825
 
840
826
  const createStampId$1 = runtime.incrementId();
@@ -848,8 +834,8 @@ const launchStampId$1 = createStampId$1();
848
834
  * - 不支持路由动画
849
835
  */
850
836
  function createMultiRouter(history, app, config, framework) {
837
+ var _a, _b, _c, _d, _e, _f;
851
838
  return tslib.__awaiter(this, void 0, void 0, function* () {
852
- var _a, _b, _c, _d, _e, _f;
853
839
  if (typeof app.onUnhandledRejection === 'function') {
854
840
  window.addEventListener('unhandledrejection', app.onUnhandledRejection);
855
841
  }
@@ -857,7 +843,7 @@ function createMultiRouter(history, app, config, framework) {
857
843
  RouterConfig.config = config;
858
844
  const handler = new MultiPageHandler(config, history);
859
845
  const launchParam = {
860
- path: config.pageName, // 多页面模式没新开一个页面相当于重启,所以直接使用当前页面路径
846
+ path: config.pageName,
861
847
  query: handler.getQuery(launchStampId$1),
862
848
  scene: 0,
863
849
  shareTicket: '',
@@ -1524,11 +1510,11 @@ function createRouter(history$1, app, config, framework) {
1524
1510
  runtime.eventCenter.trigger('__taroRouterLaunch', launchParam);
1525
1511
  (_a = app.onLaunch) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
1526
1512
  app.onError && window.addEventListener('error', e => { var _a; return (_a = app.onError) === null || _a === void 0 ? void 0 : _a.call(app, e.message); });
1527
- const render = (_c) => tslib.__awaiter(this, [_c], void 0, function* ({ location, action }) {
1528
- var _d, _e, _f, _g, _h, _j, _k, _l;
1513
+ const render = ({ location, action }) => tslib.__awaiter(this, void 0, void 0, function* () {
1514
+ var _c, _d, _e, _f, _g, _h, _j, _k;
1529
1515
  // Note: 由于下面有异步加载操作 先不要在这里去设置 handler.pathname
1530
1516
  const currentPathname = decodeURI(location.pathname);
1531
- if ((_d = window.__taroAppConfig) === null || _d === void 0 ? void 0 : _d.usingWindowScroll)
1517
+ if ((_c = window.__taroAppConfig) === null || _c === void 0 ? void 0 : _c.usingWindowScroll)
1532
1518
  window.scrollTo(0, 0);
1533
1519
  runtime.eventCenter.trigger('__taroRouterChange', {
1534
1520
  toLocation: {
@@ -1552,7 +1538,7 @@ function createRouter(history$1, app, config, framework) {
1552
1538
  path: currentPathname,
1553
1539
  query: handler.getQuery(createStampId()),
1554
1540
  };
1555
- (_e = app.onPageNotFound) === null || _e === void 0 ? void 0 : _e.call(app, notFoundEvent);
1541
+ (_d = app.onPageNotFound) === null || _d === void 0 ? void 0 : _d.call(app, notFoundEvent);
1556
1542
  runtime.eventCenter.trigger('__taroRouterNotFound', notFoundEvent);
1557
1543
  }
1558
1544
  else if (/Loading hot update .* failed./.test(error.message)) {
@@ -1569,10 +1555,10 @@ function createRouter(history$1, app, config, framework) {
1569
1555
  // context.pathname 在 universal-router 被处理过了,是发起资源请求的时候传入的 pathname,即 await router.resolve(routerPath) 这个 routerPath
1570
1556
  handler.pathname = context.pathname;
1571
1557
  const { pathname, pageConfig } = handler;
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';
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';
1576
1562
  if (pageConfig) {
1577
1563
  if (typeof pageConfig.enablePullDownRefresh === 'boolean') {
1578
1564
  enablePullDownRefresh = pageConfig.enablePullDownRefresh;
@@ -1589,7 +1575,7 @@ function createRouter(history$1, app, config, framework) {
1589
1575
  }
1590
1576
  runtime.eventCenter.trigger('__taroSetNavigationStyle', navigationStyle, navigationBarTextStyle, navigationBarBackgroundColor);
1591
1577
  const currentPage = runtime.Current.page;
1592
- const methodName = (_k = stacks.method) !== null && _k !== void 0 ? _k : '';
1578
+ const methodName = (_j = stacks.method) !== null && _j !== void 0 ? _j : '';
1593
1579
  const cacheTabs = stacks.getTabs();
1594
1580
  let shouldLoad = false;
1595
1581
  stacks.method = '';
@@ -1656,7 +1642,7 @@ function createRouter(history$1, app, config, framework) {
1656
1642
  shouldLoad = true;
1657
1643
  }
1658
1644
  if (shouldLoad || stacks.length < 1) {
1659
- const el = (_l = element.default) !== null && _l !== void 0 ? _l : element;
1645
+ const el = (_k = element.default) !== null && _k !== void 0 ? _k : element;
1660
1646
  const loadConfig = Object.assign({}, pageConfig);
1661
1647
  const stacksIndex = stacks.length;
1662
1648
  delete loadConfig['path'];
@@ -1712,7 +1698,7 @@ function handleAppMount(config, _, appId = config.appId || 'app') {
1712
1698
  app.id = appId;
1713
1699
  isPosition = false;
1714
1700
  }
1715
- const appWrapper = ((app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body);
1701
+ const appWrapper = (app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body;
1716
1702
  app.classList.add('taro_router');
1717
1703
  if (!isPosition)
1718
1704
  appWrapper.appendChild(app);
@@ -1726,7 +1712,7 @@ function handleAppMountWithTabbar(config, history, appId = config.appId || 'app'
1726
1712
  app.id = appId;
1727
1713
  isPosition = false;
1728
1714
  }
1729
- 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;
1730
1716
  app.classList.add('taro_router');
1731
1717
  const container = document.createElement('div');
1732
1718
  container.classList.add('taro-tabbar__container');
@@ -1745,11 +1731,11 @@ function handleAppMountWithTabbar(config, history, appId = config.appId || 'app'
1745
1731
  initNavigationBar(config, container);
1746
1732
  }
1747
1733
 
1748
- Object.defineProperty(exports, "createBrowserHistory", {
1734
+ Object.defineProperty(exports, 'createBrowserHistory', {
1749
1735
  enumerable: true,
1750
1736
  get: function () { return history.createBrowserHistory; }
1751
1737
  });
1752
- Object.defineProperty(exports, "createHashHistory", {
1738
+ Object.defineProperty(exports, 'createHashHistory', {
1753
1739
  enumerable: true,
1754
1740
  get: function () { return history.createHashHistory; }
1755
1741
  });
package/dist/index.d.ts CHANGED
@@ -1,9 +1,10 @@
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;
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 };
@@ -0,0 +1,66 @@
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 };
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 || config.tabBar.custom) {
227
+ if (config.tabBar == null) {
228
228
  return;
229
229
  }
230
230
  // TODO: custom-tab-bar
@@ -793,7 +793,6 @@ 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();
797
796
  });
798
797
  }
799
798
  getPageContainer(page) {
@@ -821,19 +820,6 @@ class MultiPageHandler {
821
820
  bindPageScroll(page, scrollEl, distance);
822
821
  bindPageResize(page);
823
822
  }
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
- }
837
823
  }
838
824
 
839
825
  const createStampId$1 = incrementId();
@@ -847,8 +833,8 @@ const launchStampId$1 = createStampId$1();
847
833
  * - 不支持路由动画
848
834
  */
849
835
  function createMultiRouter(history, app, config, framework) {
836
+ var _a, _b, _c, _d, _e, _f;
850
837
  return __awaiter(this, void 0, void 0, function* () {
851
- var _a, _b, _c, _d, _e, _f;
852
838
  if (typeof app.onUnhandledRejection === 'function') {
853
839
  window.addEventListener('unhandledrejection', app.onUnhandledRejection);
854
840
  }
@@ -856,7 +842,7 @@ function createMultiRouter(history, app, config, framework) {
856
842
  RouterConfig.config = config;
857
843
  const handler = new MultiPageHandler(config, history);
858
844
  const launchParam = {
859
- path: config.pageName, // 多页面模式没新开一个页面相当于重启,所以直接使用当前页面路径
845
+ path: config.pageName,
860
846
  query: handler.getQuery(launchStampId$1),
861
847
  scene: 0,
862
848
  shareTicket: '',
@@ -1523,11 +1509,11 @@ function createRouter(history, app, config, framework) {
1523
1509
  eventCenter.trigger('__taroRouterLaunch', launchParam);
1524
1510
  (_a = app.onLaunch) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
1525
1511
  app.onError && window.addEventListener('error', e => { var _a; return (_a = app.onError) === null || _a === void 0 ? void 0 : _a.call(app, e.message); });
1526
- const render = (_c) => __awaiter(this, [_c], void 0, function* ({ location, action }) {
1527
- var _d, _e, _f, _g, _h, _j, _k, _l;
1512
+ const render = ({ location, action }) => __awaiter(this, void 0, void 0, function* () {
1513
+ var _c, _d, _e, _f, _g, _h, _j, _k;
1528
1514
  // Note: 由于下面有异步加载操作 先不要在这里去设置 handler.pathname
1529
1515
  const currentPathname = decodeURI(location.pathname);
1530
- if ((_d = window.__taroAppConfig) === null || _d === void 0 ? void 0 : _d.usingWindowScroll)
1516
+ if ((_c = window.__taroAppConfig) === null || _c === void 0 ? void 0 : _c.usingWindowScroll)
1531
1517
  window.scrollTo(0, 0);
1532
1518
  eventCenter.trigger('__taroRouterChange', {
1533
1519
  toLocation: {
@@ -1551,7 +1537,7 @@ function createRouter(history, app, config, framework) {
1551
1537
  path: currentPathname,
1552
1538
  query: handler.getQuery(createStampId()),
1553
1539
  };
1554
- (_e = app.onPageNotFound) === null || _e === void 0 ? void 0 : _e.call(app, notFoundEvent);
1540
+ (_d = app.onPageNotFound) === null || _d === void 0 ? void 0 : _d.call(app, notFoundEvent);
1555
1541
  eventCenter.trigger('__taroRouterNotFound', notFoundEvent);
1556
1542
  }
1557
1543
  else if (/Loading hot update .* failed./.test(error.message)) {
@@ -1568,10 +1554,10 @@ function createRouter(history, app, config, framework) {
1568
1554
  // context.pathname 在 universal-router 被处理过了,是发起资源请求的时候传入的 pathname,即 await router.resolve(routerPath) 这个 routerPath
1569
1555
  handler.pathname = context.pathname;
1570
1556
  const { pathname, pageConfig } = handler;
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';
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';
1575
1561
  if (pageConfig) {
1576
1562
  if (typeof pageConfig.enablePullDownRefresh === 'boolean') {
1577
1563
  enablePullDownRefresh = pageConfig.enablePullDownRefresh;
@@ -1588,7 +1574,7 @@ function createRouter(history, app, config, framework) {
1588
1574
  }
1589
1575
  eventCenter.trigger('__taroSetNavigationStyle', navigationStyle, navigationBarTextStyle, navigationBarBackgroundColor);
1590
1576
  const currentPage = Current.page;
1591
- const methodName = (_k = stacks.method) !== null && _k !== void 0 ? _k : '';
1577
+ const methodName = (_j = stacks.method) !== null && _j !== void 0 ? _j : '';
1592
1578
  const cacheTabs = stacks.getTabs();
1593
1579
  let shouldLoad = false;
1594
1580
  stacks.method = '';
@@ -1655,7 +1641,7 @@ function createRouter(history, app, config, framework) {
1655
1641
  shouldLoad = true;
1656
1642
  }
1657
1643
  if (shouldLoad || stacks.length < 1) {
1658
- const el = (_l = element.default) !== null && _l !== void 0 ? _l : element;
1644
+ const el = (_k = element.default) !== null && _k !== void 0 ? _k : element;
1659
1645
  const loadConfig = Object.assign({}, pageConfig);
1660
1646
  const stacksIndex = stacks.length;
1661
1647
  delete loadConfig['path'];
@@ -1711,7 +1697,7 @@ function handleAppMount(config, _, appId = config.appId || 'app') {
1711
1697
  app.id = appId;
1712
1698
  isPosition = false;
1713
1699
  }
1714
- const appWrapper = ((app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body);
1700
+ const appWrapper = (app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body;
1715
1701
  app.classList.add('taro_router');
1716
1702
  if (!isPosition)
1717
1703
  appWrapper.appendChild(app);
@@ -1725,7 +1711,7 @@ function handleAppMountWithTabbar(config, history, appId = config.appId || 'app'
1725
1711
  app.id = appId;
1726
1712
  isPosition = false;
1727
1713
  }
1728
- 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;
1729
1715
  app.classList.add('taro_router');
1730
1716
  const container = document.createElement('div');
1731
1717
  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,2 +1,3 @@
1
- import type { MpaRouterConfig, SpaRouterConfig } from '../types/router';
2
- export declare function initNavigationBar(config: SpaRouterConfig | MpaRouterConfig, container: HTMLElement): void;
1
+ import { MpaRouterConfig, SpaRouterConfig } from '../types/router';
2
+ declare function initNavigationBar(config: SpaRouterConfig | MpaRouterConfig, container: HTMLElement): void;
3
+ export { initNavigationBar };
@@ -1,11 +1,13 @@
1
- import type { MpaRouterConfig, SpaRouterConfig } from '../../types/router';
2
- export declare class RouterConfig {
1
+ import { MpaRouterConfig, SpaRouterConfig } from '../../types/router';
2
+ 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 中
10
11
  static isPage(url?: string): boolean;
11
12
  }
13
+ export { RouterConfig };
@@ -1,6 +1,6 @@
1
- import type { AppInstance } from '@tarojs/runtime';
2
- import type { History } from 'history';
3
- import type { MpaRouterConfig } from '../../types/router';
1
+ import { AppInstance } from '@tarojs/runtime';
2
+ import { History } from "../history.js";
3
+ import { MpaRouterConfig } from '../../types/router';
4
4
  /** Note: 关于多页面应用
5
5
  * - 需要配置路由映射(根目录跳转、404 页面……)
6
6
  * - app.onPageNotFound 事件不支持
@@ -8,4 +8,5 @@ import type { MpaRouterConfig } from '../../types/router';
8
8
  * - TabBar 会多次加载
9
9
  * - 不支持路由动画
10
10
  */
11
- export declare function createMultiRouter(history: History, app: AppInstance, config: MpaRouterConfig, framework?: string): Promise<void>;
11
+ declare function createMultiRouter(history: History, app: AppInstance, config: MpaRouterConfig, framework?: string): Promise<void>;
12
+ export { createMultiRouter };
@@ -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;
19
20
  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 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 {
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 {
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 @@ export default 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): (Window & typeof globalThis) | HTMLElement;
30
+ getScrollingElement(page?: PageInstance | null): HTMLElement | (Window & typeof globalThis);
31
31
  bindPageEvents(page: PageInstance, config?: Partial<PageConfig>): void;
32
- triggerRouterChange(): void;
33
32
  }
33
+ export { MultiPageHandler as default };
@@ -1,4 +1,4 @@
1
- import { addLeadingSlash, stripBasename, Current, eventCenter } from '@tarojs/runtime';
1
+ import { addLeadingSlash, stripBasename, Current } 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,7 +106,6 @@ 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();
110
109
  });
111
110
  }
112
111
  getPageContainer(page) {
@@ -134,19 +133,6 @@ class MultiPageHandler {
134
133
  bindPageScroll(page, scrollEl, distance);
135
134
  bindPageResize(page);
136
135
  }
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
- }
150
136
  }
151
137
 
152
138
  export { MultiPageHandler as default };
@@ -1,4 +1,4 @@
1
- import type PageHandler from './page';
1
+ import PageHandler from "./page.js";
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
- export default class NavigationBarHandler {
9
+ declare class NavigationBarHandler {
10
10
  pageContext: PageHandler;
11
11
  navigationBarElement: HTMLElement;
12
12
  cache: Record<string, NavigationBarCache>;
@@ -33,4 +33,4 @@ export default class NavigationBarHandler {
33
33
  fnBtnToggleToNone(): void;
34
34
  setNavigationBarVisible(show?: any): void;
35
35
  }
36
- export {};
36
+ export { NavigationBarHandler as default };
@@ -1,9 +1,9 @@
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 {
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 {
7
7
  history: History;
8
8
  config: SpaRouterConfig;
9
9
  protected readonly defaultAnimation: RouterAnimate;
@@ -17,7 +17,7 @@ export default 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,7 +47,8 @@ export default 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): (Window & typeof globalThis) | HTMLElement;
50
+ getScrollingElement(page?: PageInstance | null): HTMLElement | (Window & typeof globalThis);
51
51
  bindPageEvents(page: PageInstance, config?: Partial<PageConfig>): void;
52
52
  triggerRouterChange(): void;
53
53
  }
54
+ export { PageHandler as default };
@@ -1,4 +1,5 @@
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;
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 };
@@ -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 = (_c) => __awaiter(this, [_c], void 0, function* ({ location, action }) {
46
- var _d, _e, _f, _g, _h, _j, _k, _l;
45
+ const render = ({ location, action }) => __awaiter(this, void 0, void 0, function* () {
46
+ var _c, _d, _e, _f, _g, _h, _j, _k;
47
47
  // Note: 由于下面有异步加载操作 先不要在这里去设置 handler.pathname
48
48
  const currentPathname = decodeURI(location.pathname);
49
- if ((_d = window.__taroAppConfig) === null || _d === void 0 ? void 0 : _d.usingWindowScroll)
49
+ if ((_c = window.__taroAppConfig) === null || _c === void 0 ? void 0 : _c.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
- (_e = app.onPageNotFound) === null || _e === void 0 ? void 0 : _e.call(app, notFoundEvent);
73
+ (_d = app.onPageNotFound) === null || _d === void 0 ? void 0 : _d.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 = ((_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';
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';
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 = (_k = stacks.method) !== null && _k !== void 0 ? _k : '';
110
+ const methodName = (_j = stacks.method) !== null && _j !== void 0 ? _j : '';
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 = (_l = element.default) !== null && _l !== void 0 ? _l : element;
177
+ const el = (_k = element.default) !== null && _k !== void 0 ? _k : 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 type { PageInstance } from '@tarojs/runtime';
1
+ import { 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 default stacks;
26
+ export { stacks as default };
package/dist/style.d.ts CHANGED
@@ -1,13 +1,14 @@
1
1
  /**
2
2
  * 插入页面动画需要的样式
3
3
  */
4
- export declare function loadAnimateStyle(ms?: number): void;
4
+ declare function loadAnimateStyle(ms?: number): void;
5
5
  /**
6
6
  * 插入路由相关样式
7
7
  */
8
- export declare function loadRouterStyle(enableTabBar: boolean, enableWindowScroll: boolean, enhanceAnimation?: boolean): void;
8
+ declare function loadRouterStyle(enableTabBar: boolean, enableWindowScroll: boolean, enhanceAnimation?: boolean): void;
9
9
  /**
10
10
  * 插入导航栏相关的样式
11
11
  */
12
- export declare function loadNavigationBarStyle(): void;
13
- export declare function addStyle(css: any): void;
12
+ declare function loadNavigationBarStyle(): void;
13
+ declare function addStyle(css: any): void;
14
+ export { loadAnimateStyle, loadRouterStyle, loadNavigationBarStyle, addStyle };
package/dist/tabbar.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  import { AppConfig } from '@tarojs/taro';
2
- import type { History } from 'history';
3
- export declare function initTabbar(config: AppConfig, history: History): void;
2
+ import { History } from "./history.js";
3
+ declare function initTabbar(config: AppConfig, history: History): void;
4
+ export { initTabbar };
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 || config.tabBar.custom) {
5
+ if (config.tabBar == null) {
6
6
  return;
7
7
  }
8
8
  // TODO: custom-tab-bar
@@ -6,5 +6,6 @@ declare class RoutesAlias {
6
6
  getAlias: (url?: string) => string;
7
7
  getAll: (url?: string) => string[];
8
8
  }
9
- export declare const routesAlias: RoutesAlias;
10
- export * from './navigate';
9
+ declare const routesAlias: RoutesAlias;
10
+ export { routesAlias };
11
+ export * from "./navigate.js";
@@ -1,9 +1,10 @@
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: {
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: {
6
6
  backgroundColor: string;
7
7
  frontColor: string;
8
8
  }): void;
9
- export declare function setNavigationBarLoading(loading: boolean): void;
9
+ declare function setNavigationBarLoading(loading: boolean): void;
10
+ export { isWeixin, isDingTalk, setMpaTitle, setTitle, setNavigationBarStyle, setNavigationBarLoading };
package/package.json CHANGED
@@ -1,9 +1,7 @@
1
1
  {
2
2
  "name": "@tarojs/router",
3
- "version": "4.0.1-alpha.0",
3
+ "version": "4.0.1",
4
4
  "description": "Taro-router",
5
- "author": "O2Team",
6
- "license": "MIT",
7
5
  "browser": "dist/index.js",
8
6
  "main:h5": "dist/index.esm.js",
9
7
  "main": "dist/index.js",
@@ -22,34 +20,47 @@
22
20
  "keywords": [
23
21
  "router"
24
22
  ],
25
- "engines": {
26
- "node": ">= 18"
27
- },
23
+ "author": "O2Team",
24
+ "license": "MIT",
28
25
  "dependencies": {
29
26
  "dingtalk-jsapi": "~2.15.2",
30
- "history": "^5.3.0",
27
+ "history": "^5.1.0",
31
28
  "mobile-detect": "^1.4.2",
32
- "query-string": "^9.0.0",
29
+ "query-string": "^7.1.1",
33
30
  "tslib": "^2.6.2",
34
- "universal-router": "^9.2.0"
31
+ "universal-router": "^8.3.0"
35
32
  },
36
33
  "devDependencies": {
37
- "@tarojs/components": "4.0.1-alpha.0",
38
- "@tarojs/runtime": "4.0.1-alpha.0",
39
- "@tarojs/shared": "4.0.1-alpha.0",
40
- "@tarojs/taro": "4.0.1-alpha.0"
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"
41
50
  },
42
51
  "peerDependencies": {
43
- "@tarojs/runtime": "4.0.1-alpha.0",
44
- "@tarojs/taro": "4.0.1-alpha.0",
45
- "@tarojs/shared": "4.0.1-alpha.0"
52
+ "@tarojs/runtime": "4.0.1",
53
+ "@tarojs/taro": "4.0.1",
54
+ "@tarojs/shared": "4.0.1"
46
55
  },
47
56
  "scripts": {
48
- "prod": "pnpm run build",
49
57
  "prebuild": "pnpm run clean",
50
58
  "build": "pnpm run rollup --environment NODE_ENV:production",
51
- "clean": "rimraf --impl=move-remove ./dist",
59
+ "clean": "rimraf ./dist",
52
60
  "dev": "pnpm run rollup --environment NODE_ENV:development -w",
53
- "rollup": "rollup --config rollup.config.mts --configPlugin typescript"
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"
54
65
  }
55
66
  }