@tarojs/router 4.0.0-beta.8 → 4.0.0-beta.80
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/dist/api.js +26 -1
- package/dist/events/resize.js +12 -6
- package/dist/history.js +3 -2
- package/dist/index.cjs.d.ts +8 -2
- package/dist/index.cjs.js +566 -105
- package/dist/index.esm.d.ts +8 -2
- package/dist/index.esm.js +565 -107
- package/dist/index.js +4 -1
- package/dist/navigationBar.d.ts +3 -0
- package/dist/navigationBar.js +44 -0
- package/dist/router/mpa.js +19 -3
- package/dist/router/navigation-bar.d.ts +36 -0
- package/dist/router/navigation-bar.js +252 -0
- package/dist/router/page.d.ts +3 -1
- package/dist/router/page.js +6 -0
- package/dist/router/spa.js +24 -6
- package/dist/style.d.ts +5 -1
- package/dist/style.js +95 -1
- package/dist/utils/index.js +0 -1
- package/dist/utils/navigate.d.ts +8 -2
- package/dist/utils/navigate.js +25 -19
- package/package.json +7 -5
- package/types/api.d.ts +5 -0
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);
|
|
@@ -37,6 +39,10 @@ function navigate(option, method) {
|
|
|
37
39
|
const { success, complete, fail } = option;
|
|
38
40
|
const unListen = history.listen(() => {
|
|
39
41
|
const res = { errMsg: `${method}:ok` };
|
|
42
|
+
if (method === 'navigateTo') {
|
|
43
|
+
res.eventChannel = routeEvtChannel;
|
|
44
|
+
routeEvtChannel.addEvents(option.events);
|
|
45
|
+
}
|
|
40
46
|
success === null || success === void 0 ? void 0 : success(res);
|
|
41
47
|
complete === null || complete === void 0 ? void 0 : complete(res);
|
|
42
48
|
resolve(res);
|
|
@@ -46,6 +52,20 @@ function navigate(option, method) {
|
|
|
46
52
|
if ('url' in option) {
|
|
47
53
|
const pathPieces = processNavigateUrl(option);
|
|
48
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
|
+
}
|
|
49
69
|
if (method === 'navigateTo') {
|
|
50
70
|
history.push(pathPieces, state);
|
|
51
71
|
}
|
|
@@ -71,7 +91,12 @@ function navigate(option, method) {
|
|
|
71
91
|
const res = { errMsg: `${method}:fail ${error.message || error}` };
|
|
72
92
|
fail === null || fail === void 0 ? void 0 : fail(res);
|
|
73
93
|
complete === null || complete === void 0 ? void 0 : complete(res);
|
|
74
|
-
|
|
94
|
+
if (fail || complete) {
|
|
95
|
+
return resolve(res);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
return reject(res);
|
|
99
|
+
}
|
|
75
100
|
}
|
|
76
101
|
});
|
|
77
102
|
});
|
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/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
|
}
|
package/dist/index.cjs.d.ts
CHANGED
|
@@ -54,7 +54,13 @@ declare class RoutesAlias {
|
|
|
54
54
|
declare const routesAlias: RoutesAlias;
|
|
55
55
|
declare const isWeixin: () => boolean;
|
|
56
56
|
declare const isDingTalk: () => boolean;
|
|
57
|
-
declare function
|
|
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;
|
|
58
64
|
declare function handleAppMount(config: SpaRouterConfig | MpaRouterConfig, _: History, appId?: string): void;
|
|
59
65
|
declare function handleAppMountWithTabbar(config: SpaRouterConfig | MpaRouterConfig, history: History, appId?: string): void;
|
|
60
|
-
export { navigateTo, redirectTo, navigateBack, switchTab, reLaunch, getCurrentPages, history, setHistory, createMpaHistory, createBrowserHistory, createHashHistory, setHistoryMode, prependBasename, createMultiRouter, createRouter, routesAlias, isWeixin, isDingTalk, setTitle, handleAppMount, handleAppMountWithTabbar };
|
|
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 };
|