@tarojs/router 4.0.0-beta.77 → 4.0.0-beta.79

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
 
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 };
package/dist/api.js CHANGED
@@ -16,14 +16,13 @@ function processNavigateUrl(option) {
16
16
  const parts = routesAlias.getOrigin(history.location.pathname).split('/');
17
17
  parts.pop();
18
18
  pathPieces.pathname.split('/').forEach((item) => {
19
- if (item === '.')
19
+ if (item === '.') {
20
20
  return;
21
+ }
21
22
  item === '..' ? parts.pop() : parts.push(item);
22
23
  });
23
24
  pathPieces.pathname = parts.join('/');
24
25
  }
25
- // 确保是 / 开头的路径
26
- pathPieces.pathname = addLeadingSlash(pathPieces.pathname);
27
26
  // 处理自定义路由
28
27
  pathPieces.pathname = routesAlias.getAlias(addLeadingSlash(pathPieces.pathname));
29
28
  // 处理 basename
@@ -53,6 +52,20 @@ function navigate(option, method) {
53
52
  if ('url' in option) {
54
53
  const pathPieces = processNavigateUrl(option);
55
54
  const state = { timestamp: Date.now() };
55
+ if (pathPieces.pathname) {
56
+ const originPath = routesAlias.getOrigin(pathPieces.pathname);
57
+ if (!RouterConfig.isPage(addLeadingSlash(originPath)) && !RouterConfig.isPage(addLeadingSlash(pathPieces.pathname))) {
58
+ const res = { errMsg: `${method}:fail page ${originPath} is not found` };
59
+ fail === null || fail === void 0 ? void 0 : fail(res);
60
+ complete === null || complete === void 0 ? void 0 : complete(res);
61
+ if (fail || complete) {
62
+ return resolve(res);
63
+ }
64
+ else {
65
+ return reject(res);
66
+ }
67
+ }
68
+ }
56
69
  if (method === 'navigateTo') {
57
70
  history.push(pathPieces, state);
58
71
  }
@@ -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
@@ -15,8 +15,7 @@ var UniversalRouter = require('universal-router');
15
15
  function loadAnimateStyle(ms = 300) {
16
16
  const css = `
17
17
  body {
18
- /* 防止 iOS 页面滚动 */
19
- overflow: hidden;
18
+ overflow: hidden; // 防止 iOS 页面滚动
20
19
  }
21
20
  .taro_router > .taro_page {
22
21
  position: absolute;
@@ -73,9 +72,8 @@ ${enableTabBar ? `
73
72
  }
74
73
 
75
74
  ` : ''}
76
- .taro_page_shade:has(+.taro_page_stationed),
77
- .taro_page_shade.taro_tabbar_page,
78
- .taro_router > .taro_page.taro_page_show.taro_page_stationed:not(.taro_page_shade):not(.taro_tabbar_page):not(:last-child):has(+.taro_page_stationed) {
75
+ .taro_page_shade,
76
+ .taro_router > .taro_page.taro_page_show.taro_page_stationed:not(.taro_page_shade):not(.taro_tabbar_page):not(:last-child) {
79
77
  display: none;
80
78
  }
81
79
  `;
@@ -143,7 +141,7 @@ function loadNavigationBarStyle() {
143
141
  to {
144
142
  transform: rotate(360deg);
145
143
  }
146
- }
144
+ }
147
145
 
148
146
  .taro-navigation-bar-no-icon > .taro-navigation-bar-home {
149
147
  display: none;
@@ -265,9 +263,8 @@ class RouterConfig {
265
263
  return this.router.mode || 'hash';
266
264
  }
267
265
  static get customRoutes() { return this.router.customRoutes || {}; }
268
- // 这个方法不考虑 basename 和 customRoutes,只判断原始的 url 是否在 pages 中
269
266
  static isPage(url = '') {
270
- return this.pages.findIndex(e => runtime.addLeadingSlash(e) === url) !== -1;
267
+ return this.pages.findIndex(e => prependBasename(e) === url) !== -1;
271
268
  }
272
269
  }
273
270
 
@@ -536,14 +533,13 @@ function processNavigateUrl(option) {
536
533
  const parts = routesAlias.getOrigin(exports.history.location.pathname).split('/');
537
534
  parts.pop();
538
535
  pathPieces.pathname.split('/').forEach((item) => {
539
- if (item === '.')
536
+ if (item === '.') {
540
537
  return;
538
+ }
541
539
  item === '..' ? parts.pop() : parts.push(item);
542
540
  });
543
541
  pathPieces.pathname = parts.join('/');
544
542
  }
545
- // 确保是 / 开头的路径
546
- pathPieces.pathname = runtime.addLeadingSlash(pathPieces.pathname);
547
543
  // 处理自定义路由
548
544
  pathPieces.pathname = routesAlias.getAlias(runtime.addLeadingSlash(pathPieces.pathname));
549
545
  // 处理 basename
@@ -573,6 +569,20 @@ function navigate(option, method) {
573
569
  if ('url' in option) {
574
570
  const pathPieces = processNavigateUrl(option);
575
571
  const state = { timestamp: Date.now() };
572
+ if (pathPieces.pathname) {
573
+ const originPath = routesAlias.getOrigin(pathPieces.pathname);
574
+ if (!RouterConfig.isPage(runtime.addLeadingSlash(originPath)) && !RouterConfig.isPage(runtime.addLeadingSlash(pathPieces.pathname))) {
575
+ const res = { errMsg: `${method}:fail page ${originPath} is not found` };
576
+ fail === null || fail === void 0 ? void 0 : fail(res);
577
+ complete === null || complete === void 0 ? void 0 : complete(res);
578
+ if (fail || complete) {
579
+ return resolve(res);
580
+ }
581
+ else {
582
+ return reject(res);
583
+ }
584
+ }
585
+ }
576
586
  if (method === 'navigateTo') {
577
587
  exports.history.push(pathPieces, state);
578
588
  }
@@ -843,8 +853,8 @@ const launchStampId$1 = createStampId$1();
843
853
  * - 不支持路由动画
844
854
  */
845
855
  function createMultiRouter(history, app, config, framework) {
856
+ var _a, _b, _c, _d, _e, _f;
846
857
  return tslib.__awaiter(this, void 0, void 0, function* () {
847
- var _a, _b, _c, _d, _e, _f;
848
858
  if (typeof app.onUnhandledRejection === 'function') {
849
859
  window.addEventListener('unhandledrejection', app.onUnhandledRejection);
850
860
  }
@@ -852,7 +862,7 @@ function createMultiRouter(history, app, config, framework) {
852
862
  RouterConfig.config = config;
853
863
  const handler = new MultiPageHandler(config, history);
854
864
  const launchParam = {
855
- path: config.pageName, // 多页面模式没新开一个页面相当于重启,所以直接使用当前页面路径
865
+ path: config.pageName,
856
866
  query: handler.getQuery(launchStampId$1),
857
867
  scene: 0,
858
868
  shareTicket: '',
@@ -931,7 +941,7 @@ class NavigationBarHandler {
931
941
  });
932
942
  }
933
943
  toHomeFn() {
934
- reLaunch({ url: this.pageContext.originHomePage });
944
+ reLaunch({ url: this.pageContext.homePage });
935
945
  }
936
946
  backFn() {
937
947
  navigateBack();
@@ -980,7 +990,7 @@ class NavigationBarHandler {
980
990
  this.setNavigationLoading();
981
991
  }
982
992
  setCacheValue() {
983
- const currentPage = this.pageContext.originPathname;
993
+ const currentPage = this.pageContext.currentPage;
984
994
  if (typeof this.cache[currentPage] !== 'object') {
985
995
  this.cache[currentPage] = {};
986
996
  }
@@ -1011,7 +1021,7 @@ class NavigationBarHandler {
1011
1021
  var _a;
1012
1022
  if (!this.navigationBarElement)
1013
1023
  return;
1014
- const currentPage = this.pageContext.originPathname;
1024
+ const currentPage = this.pageContext.currentPage;
1015
1025
  let isShow;
1016
1026
  if (typeof show === 'boolean') {
1017
1027
  isShow = show;
@@ -1036,7 +1046,7 @@ class NavigationBarHandler {
1036
1046
  var _a, _b, _c;
1037
1047
  if (!this.navigationBarElement)
1038
1048
  return;
1039
- const currentPage = this.pageContext.originPathname;
1049
+ const currentPage = this.pageContext.currentPage;
1040
1050
  let color;
1041
1051
  if (typeof backgroundColor === 'string') {
1042
1052
  color = backgroundColor;
@@ -1060,7 +1070,7 @@ class NavigationBarHandler {
1060
1070
  var _a, _b, _c;
1061
1071
  if (!this.navigationBarElement)
1062
1072
  return;
1063
- const currentPage = this.pageContext.originPathname;
1073
+ const currentPage = this.pageContext.currentPage;
1064
1074
  let color;
1065
1075
  if (typeof fontColor === 'string') {
1066
1076
  color = fontColor;
@@ -1082,7 +1092,7 @@ class NavigationBarHandler {
1082
1092
  }
1083
1093
  setTitle(title) {
1084
1094
  var _a, _b, _c;
1085
- const currentPage = this.pageContext.originPathname;
1095
+ const currentPage = this.pageContext.currentPage;
1086
1096
  let proceedTitle;
1087
1097
  if (typeof title === 'string') {
1088
1098
  proceedTitle = title;
@@ -1163,7 +1173,6 @@ class PageHandler {
1163
1173
  this.defaultAnimation = { duration: 300, delay: 50 };
1164
1174
  this.config = config;
1165
1175
  this.homePage = runtime.getHomePage(this.routes[0].path, this.basename, this.customRoutes, this.config.entryPagePath);
1166
- this.originHomePage = this.config.entryPagePath || this.routes[0].path || this.basename;
1167
1176
  this.mount();
1168
1177
  this.navigationBarHandler = new NavigationBarHandler(this);
1169
1178
  }
@@ -1197,14 +1206,14 @@ class PageHandler {
1197
1206
  }
1198
1207
  set pathname(p) { this.router.pathname = p; }
1199
1208
  get pathname() { return this.router.pathname; }
1200
- // Note: 把 pathname 转换为原始路径,主要是处理 customRoutes 和 basename
1201
- get originPathname() { return routesAlias.getOrigin(runtime.addLeadingSlash(runtime.stripBasename(this.pathname, this.basename))); }
1202
1209
  get basename() { return this.router.basename || ''; }
1203
1210
  get pageConfig() {
1211
+ const routePath = runtime.addLeadingSlash(runtime.stripBasename(this.pathname, this.basename));
1204
1212
  const homePage = runtime.addLeadingSlash(this.homePage);
1205
1213
  return this.routes.find(r => {
1214
+ var _a;
1206
1215
  const pagePath = runtime.addLeadingSlash(r.path);
1207
- return [pagePath, homePage].includes(this.originPathname);
1216
+ return [pagePath, homePage].includes(routePath) || ((_a = routesAlias.getConfig(pagePath)) === null || _a === void 0 ? void 0 : _a.includes(routePath));
1208
1217
  });
1209
1218
  }
1210
1219
  isTabBar(pathname) {
@@ -1394,35 +1403,24 @@ class PageHandler {
1394
1403
  });
1395
1404
  }
1396
1405
  }
1397
- hide(page, animation = false) {
1398
- var _a, _b, _c, _d, _e, _f, _g;
1406
+ hide(page) {
1407
+ var _a;
1399
1408
  if (!page)
1400
1409
  return;
1401
1410
  // NOTE: 修复多页并发问题,此处可能因为路由跳转过快,执行时页面可能还没有创建成功
1402
1411
  const pageEl = this.getPageContainer(page);
1403
1412
  if (pageEl) {
1404
- if (animation) {
1405
- if (this.hideTimer) {
1406
- clearTimeout(this.hideTimer);
1407
- this.hideTimer = null;
1408
- (_c = (_b = (_a = this.lastHidePage) === null || _a === void 0 ? void 0 : _a.classList) === null || _b === void 0 ? void 0 : _b.add) === null || _c === void 0 ? void 0 : _c.call(_b, 'taro_page_shade');
1409
- }
1410
- this.lastHidePage = pageEl;
1411
- this.hideTimer = setTimeout(() => {
1412
- this.hideTimer = null;
1413
- pageEl.classList.add('taro_page_shade');
1414
- }, this.animationDuration + this.animationDelay);
1415
- (_d = page.onHide) === null || _d === void 0 ? void 0 : _d.call(page);
1416
- }
1417
- else {
1418
- if (this.hideTimer) {
1419
- clearTimeout(this.hideTimer);
1420
- this.hideTimer = null;
1421
- (_g = (_f = (_e = this.lastHidePage) === null || _e === void 0 ? void 0 : _e.classList) === null || _f === void 0 ? void 0 : _f.add) === null || _g === void 0 ? void 0 : _g.call(_f, 'taro_page_shade');
1422
- }
1413
+ if (this.hideTimer) {
1414
+ clearTimeout(this.hideTimer);
1415
+ this.hideTimer = null;
1423
1416
  pageEl.classList.add('taro_page_shade');
1424
- this.lastHidePage = pageEl;
1425
1417
  }
1418
+ this.lastHidePage = pageEl;
1419
+ this.hideTimer = setTimeout(() => {
1420
+ this.hideTimer = null;
1421
+ pageEl.classList.add('taro_page_shade');
1422
+ }, this.animationDuration + this.animationDelay);
1423
+ (_a = page.onHide) === null || _a === void 0 ? void 0 : _a.call(page);
1426
1424
  }
1427
1425
  else {
1428
1426
  setTimeout(() => this.hide(page), 0);
@@ -1514,10 +1512,10 @@ function createRouter(history$1, app, config, framework) {
1514
1512
  runtime.eventCenter.trigger('__taroRouterLaunch', launchParam);
1515
1513
  (_a = app.onLaunch) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
1516
1514
  app.onError && window.addEventListener('error', e => { var _a; return (_a = app.onError) === null || _a === void 0 ? void 0 : _a.call(app, e.message); });
1517
- const render = (_c) => tslib.__awaiter(this, [_c], void 0, function* ({ location, action }) {
1518
- var _d, _e, _f, _g, _h, _j, _k, _l;
1515
+ const render = ({ location, action }) => tslib.__awaiter(this, void 0, void 0, function* () {
1516
+ var _c, _d, _e, _f, _g, _h, _j, _k;
1519
1517
  handler.pathname = decodeURI(location.pathname);
1520
- if ((_d = window.__taroAppConfig) === null || _d === void 0 ? void 0 : _d.usingWindowScroll)
1518
+ if ((_c = window.__taroAppConfig) === null || _c === void 0 ? void 0 : _c.usingWindowScroll)
1521
1519
  window.scrollTo(0, 0);
1522
1520
  runtime.eventCenter.trigger('__taroRouterChange', {
1523
1521
  toLocation: {
@@ -1536,7 +1534,7 @@ function createRouter(history$1, app, config, framework) {
1536
1534
  path: handler.pathname,
1537
1535
  query: handler.getQuery(createStampId()),
1538
1536
  };
1539
- (_e = app.onPageNotFound) === null || _e === void 0 ? void 0 : _e.call(app, notFoundEvent);
1537
+ (_d = app.onPageNotFound) === null || _d === void 0 ? void 0 : _d.call(app, notFoundEvent);
1540
1538
  runtime.eventCenter.trigger('__taroRouterNotFound', notFoundEvent);
1541
1539
  }
1542
1540
  else if (/Loading hot update .* failed./.test(error.message)) {
@@ -1550,10 +1548,10 @@ function createRouter(history$1, app, config, framework) {
1550
1548
  if (!element)
1551
1549
  return;
1552
1550
  const pageConfig = handler.pageConfig;
1553
- let enablePullDownRefresh = ((_f = config === null || config === void 0 ? void 0 : config.window) === null || _f === void 0 ? void 0 : _f.enablePullDownRefresh) || false;
1554
- let navigationStyle = ((_g = config === null || config === void 0 ? void 0 : config.window) === null || _g === void 0 ? void 0 : _g.navigationStyle) || 'default';
1555
- let navigationBarTextStyle = ((_h = config === null || config === void 0 ? void 0 : config.window) === null || _h === void 0 ? void 0 : _h.navigationBarTextStyle) || 'white';
1556
- let navigationBarBackgroundColor = ((_j = config === null || config === void 0 ? void 0 : config.window) === null || _j === void 0 ? void 0 : _j.navigationBarBackgroundColor) || '#000000';
1551
+ let enablePullDownRefresh = ((_e = config === null || config === void 0 ? void 0 : config.window) === null || _e === void 0 ? void 0 : _e.enablePullDownRefresh) || false;
1552
+ let navigationStyle = ((_f = config === null || config === void 0 ? void 0 : config.window) === null || _f === void 0 ? void 0 : _f.navigationStyle) || 'default';
1553
+ let navigationBarTextStyle = ((_g = config === null || config === void 0 ? void 0 : config.window) === null || _g === void 0 ? void 0 : _g.navigationBarTextStyle) || 'white';
1554
+ let navigationBarBackgroundColor = ((_h = config === null || config === void 0 ? void 0 : config.window) === null || _h === void 0 ? void 0 : _h.navigationBarBackgroundColor) || '#000000';
1557
1555
  if (pageConfig) {
1558
1556
  if (typeof pageConfig.enablePullDownRefresh === 'boolean') {
1559
1557
  enablePullDownRefresh = pageConfig.enablePullDownRefresh;
@@ -1571,7 +1569,7 @@ function createRouter(history$1, app, config, framework) {
1571
1569
  runtime.eventCenter.trigger('__taroSetNavigationStyle', navigationStyle, navigationBarTextStyle, navigationBarBackgroundColor);
1572
1570
  const currentPage = runtime.Current.page;
1573
1571
  const pathname = handler.pathname;
1574
- const methodName = (_k = stacks.method) !== null && _k !== void 0 ? _k : '';
1572
+ const methodName = (_j = stacks.method) !== null && _j !== void 0 ? _j : '';
1575
1573
  const cacheTabs = stacks.getTabs();
1576
1574
  let shouldLoad = false;
1577
1575
  stacks.method = '';
@@ -1590,7 +1588,6 @@ function createRouter(history$1, app, config, framework) {
1590
1588
  if (handler.isSamePage(currentPage))
1591
1589
  return;
1592
1590
  if (handler.isTabBar(currentPage.path)) {
1593
- // NOTE: 从 tabBar 页面切换到 tabBar 页面
1594
1591
  handler.hide(currentPage);
1595
1592
  stacks.pushTab(currentPage.path.split('?')[0]);
1596
1593
  }
@@ -1634,11 +1631,11 @@ function createRouter(history$1, app, config, framework) {
1634
1631
  shouldLoad = true;
1635
1632
  }
1636
1633
  else if (action === 'PUSH') {
1637
- handler.hide(currentPage, true);
1634
+ handler.hide(currentPage);
1638
1635
  shouldLoad = true;
1639
1636
  }
1640
1637
  if (shouldLoad || stacks.length < 1) {
1641
- const el = (_l = element.default) !== null && _l !== void 0 ? _l : element;
1638
+ const el = (_k = element.default) !== null && _k !== void 0 ? _k : element;
1642
1639
  const loadConfig = Object.assign({}, pageConfig);
1643
1640
  const stacksIndex = stacks.length;
1644
1641
  delete loadConfig['path'];
@@ -1727,11 +1724,11 @@ function handleAppMountWithTabbar(config, history, appId = config.appId || 'app'
1727
1724
  initNavigationBar(config, container);
1728
1725
  }
1729
1726
 
1730
- Object.defineProperty(exports, "createBrowserHistory", {
1727
+ Object.defineProperty(exports, 'createBrowserHistory', {
1731
1728
  enumerable: true,
1732
1729
  get: function () { return history.createBrowserHistory; }
1733
1730
  });
1734
- Object.defineProperty(exports, "createHashHistory", {
1731
+ Object.defineProperty(exports, 'createHashHistory', {
1735
1732
  enumerable: true,
1736
1733
  get: function () { return history.createHashHistory; }
1737
1734
  });
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 };