@tarojs/router 4.0.0-canary.9 → 4.0.0

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[];
package/dist/api.js CHANGED
@@ -1,11 +1,13 @@
1
1
  import { __awaiter } from 'tslib';
2
2
  import { addLeadingSlash } from '@tarojs/runtime';
3
+ import { EventChannel } from '@tarojs/shared';
3
4
  import { parsePath } from 'history';
4
5
  import { history, prependBasename } from './history.js';
5
6
  import { RouterConfig } from './router/index.js';
6
7
  import stacks from './router/stack.js';
7
8
  import { routesAlias } from './utils/index.js';
8
9
 
10
+ const routeEvtChannel = EventChannel.routeChannel;
9
11
  function processNavigateUrl(option) {
10
12
  var _a;
11
13
  const pathPieces = parsePath(option.url);
@@ -14,13 +16,14 @@ function processNavigateUrl(option) {
14
16
  const parts = routesAlias.getOrigin(history.location.pathname).split('/');
15
17
  parts.pop();
16
18
  pathPieces.pathname.split('/').forEach((item) => {
17
- if (item === '.') {
19
+ if (item === '.')
18
20
  return;
19
- }
20
21
  item === '..' ? parts.pop() : parts.push(item);
21
22
  });
22
23
  pathPieces.pathname = parts.join('/');
23
24
  }
25
+ // 确保是 / 开头的路径
26
+ pathPieces.pathname = addLeadingSlash(pathPieces.pathname);
24
27
  // 处理自定义路由
25
28
  pathPieces.pathname = routesAlias.getAlias(addLeadingSlash(pathPieces.pathname));
26
29
  // 处理 basename
@@ -37,6 +40,10 @@ function navigate(option, method) {
37
40
  const { success, complete, fail } = option;
38
41
  const unListen = history.listen(() => {
39
42
  const res = { errMsg: `${method}:ok` };
43
+ if (method === 'navigateTo') {
44
+ res.eventChannel = routeEvtChannel;
45
+ routeEvtChannel.addEvents(option.events);
46
+ }
40
47
  success === null || success === void 0 ? void 0 : success(res);
41
48
  complete === null || complete === void 0 ? void 0 : complete(res);
42
49
  resolve(res);
@@ -47,6 +54,7 @@ function navigate(option, method) {
47
54
  const pathPieces = processNavigateUrl(option);
48
55
  const state = { timestamp: Date.now() };
49
56
  if (method === 'navigateTo') {
57
+ // Note: 由于 spa 会针对弱网情况下,短时间内多次跳转同一个页面跳转加了锁,后续如果有用户反馈返回无效,那可能是这个问题
50
58
  history.push(pathPieces, state);
51
59
  }
52
60
  else if (method === 'redirectTo' || method === 'switchTab') {
@@ -71,7 +79,12 @@ function navigate(option, method) {
71
79
  const res = { errMsg: `${method}:fail ${error.message || error}` };
72
80
  fail === null || fail === void 0 ? void 0 : fail(res);
73
81
  complete === null || complete === void 0 ? void 0 : complete(res);
74
- reject(res);
82
+ if (fail || complete) {
83
+ return resolve(res);
84
+ }
85
+ else {
86
+ return reject(res);
87
+ }
75
88
  }
76
89
  });
77
90
  });
@@ -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;
@@ -2,12 +2,18 @@ let pageResizeFn;
2
2
  function bindPageResize(page) {
3
3
  pageResizeFn && window.removeEventListener('resize', pageResizeFn);
4
4
  pageResizeFn = function () {
5
- page.onResize && page.onResize({
6
- size: {
7
- windowHeight: window.innerHeight,
8
- windowWidth: window.innerWidth
9
- }
10
- });
5
+ if (page.onResize) {
6
+ const mediaQuery = window.matchMedia('(orientation: portrait)');
7
+ page.onResize({
8
+ deviceOrientation: mediaQuery.matches ? 'portrait' : 'landscape',
9
+ size: {
10
+ windowHeight: window.innerHeight,
11
+ windowWidth: window.innerWidth,
12
+ screenHeight: window.screen.height,
13
+ screenWidth: window.screen.width,
14
+ }
15
+ });
16
+ }
11
17
  };
12
18
  window.addEventListener('resize', pageResizeFn, false);
13
19
  }
@@ -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/history.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { addLeadingSlash } from '@tarojs/runtime';
1
2
  import { createBrowserHistory, createHashHistory, Action } from 'history';
2
3
  export { createBrowserHistory, createHashHistory } from 'history';
3
4
  import { RouterConfig } from './router/index.js';
@@ -25,14 +26,14 @@ class MpaHistory {
25
26
  }
26
27
  parseUrl(to) {
27
28
  let url = to.pathname || '';
28
- if (RouterConfig.isPage(url)) {
29
+ if (RouterConfig.isPage(addLeadingSlash(url))) {
29
30
  url += '.html';
30
31
  }
31
32
  if (to.search) {
32
33
  url += `?${to.search}`;
33
34
  }
34
35
  if (to.hash) {
35
- url += `#${to.hash}`;
36
+ url += to.hash.startsWith('#') ? to.hash : `#${to.hash}`;
36
37
  }
37
38
  return url;
38
39
  }