@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 +8 -8
- package/README.md +1 -1
- package/dist/api.d.ts +6 -7
- package/dist/api.js +16 -3
- package/dist/events/resize.d.ts +2 -3
- package/dist/events/resize.js +12 -6
- package/dist/events/scroll.d.ts +2 -3
- package/dist/history.d.ts +10 -8
- package/dist/history.js +3 -2
- package/dist/index.cjs.js +629 -147
- package/dist/index.d.ts +9 -10
- package/dist/index.esm.js +626 -147
- package/dist/index.js +6 -3
- package/dist/navigationBar.d.ts +2 -0
- package/dist/navigationBar.js +44 -0
- package/dist/router/index.d.ts +3 -4
- package/dist/router/index.js +3 -2
- package/dist/router/mpa.d.ts +4 -5
- package/dist/router/mpa.js +21 -5
- package/dist/router/multi-page.d.ts +7 -8
- package/dist/router/navigation-bar.d.ts +36 -0
- package/dist/router/navigation-bar.js +252 -0
- package/dist/router/page.d.ts +13 -10
- package/dist/router/page.js +34 -15
- package/dist/router/spa.d.ts +4 -5
- package/dist/router/spa.js +55 -24
- package/dist/router/stack.d.ts +2 -2
- package/dist/style.d.ts +7 -4
- package/dist/style.js +103 -3
- package/dist/tabbar.d.ts +2 -3
- package/dist/utils/index.d.ts +2 -3
- package/dist/utils/index.js +0 -1
- package/dist/utils/navigate.d.ts +9 -4
- package/dist/utils/navigate.js +25 -19
- package/package.json +18 -27
- package/types/api.d.ts +5 -0
- package/types/router.d.ts +2 -0
- package/dist/index.cjs.d.ts +0 -60
- package/dist/index.esm.d.ts +0 -60
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 [
|
|
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
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
|
-
|
|
82
|
+
if (fail || complete) {
|
|
83
|
+
return resolve(res);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
return reject(res);
|
|
87
|
+
}
|
|
75
88
|
}
|
|
76
89
|
});
|
|
77
90
|
});
|
package/dist/events/resize.d.ts
CHANGED
|
@@ -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;
|
package/dist/events/resize.js
CHANGED
|
@@ -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
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
}
|
package/dist/events/scroll.d.ts
CHANGED
|
@@ -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 {
|
|
2
|
-
import {
|
|
3
|
-
|
|
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
|
-
|
|
23
|
-
declare function
|
|
24
|
-
export
|
|
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
|
}
|