@tarojs/router 4.0.0-alpha.2 → 4.0.0-alpha.21
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/dist/api.d.ts +6 -7
- package/dist/api.js +10 -17
- package/dist/events/resize.d.ts +2 -3
- package/dist/events/scroll.d.ts +2 -3
- package/dist/history.d.ts +10 -8
- package/dist/history.js +2 -1
- package/dist/index.cjs.js +363 -226
- package/dist/index.d.ts +9 -10
- package/dist/index.esm.js +362 -226
- package/dist/index.js +3 -3
- package/dist/navigationBar.d.ts +2 -2
- package/dist/navigationBar.js +24 -7
- 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 +12 -7
- package/dist/router/multi-page.d.ts +7 -8
- package/dist/router/navigation-bar.d.ts +8 -4
- package/dist/router/navigation-bar.js +62 -19
- package/dist/router/page.d.ts +11 -10
- package/dist/router/page.js +26 -14
- package/dist/router/spa.d.ts +4 -5
- package/dist/router/spa.js +51 -27
- package/dist/router/stack.d.ts +2 -2
- package/dist/style.d.ts +4 -5
- package/dist/style.js +52 -13
- package/dist/tabbar.d.ts +2 -3
- package/dist/utils/index.d.ts +2 -3
- package/dist/utils/navigate.d.ts +6 -6
- package/dist/utils/navigate.js +5 -2
- package/package.json +18 -27
- package/types/api.d.ts +5 -0
- package/dist/index.cjs.d.ts +0 -65
- package/dist/index.esm.d.ts +0 -65
package/dist/router/spa.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __awaiter } from 'tslib';
|
|
2
|
-
import { incrementId, addLeadingSlash, eventCenter, stripBasename, Current, createPageConfig, hooks, stringify } from '@tarojs/runtime';
|
|
2
|
+
import { incrementId, addLeadingSlash, eventCenter, stripBasename, Current, safeExecute, createPageConfig, hooks, stringify } from '@tarojs/runtime';
|
|
3
3
|
import { Action } from 'history';
|
|
4
4
|
import UniversalRouter from 'universal-router';
|
|
5
5
|
import { prependBasename } from '../history.js';
|
|
@@ -17,6 +17,10 @@ function createRouter(history, app, config, framework) {
|
|
|
17
17
|
}
|
|
18
18
|
RouterConfig.config = config;
|
|
19
19
|
const handler = new PageHandler(config, history);
|
|
20
|
+
// Note: 弱网情况下,快速切换 tab,会造成同个页面实例被多次挂在到页面上,原因是资源请求是异步的,短时间内发起多个请求,
|
|
21
|
+
// 会在资源加载完成后,同时走到挂载的逻辑,造成 pageStampId 更新不及时,两个 page 的Id 相同,后面很多操作是通过 getElementById 来进行的
|
|
22
|
+
// 所以需要加一个锁来应对这个情况
|
|
23
|
+
const pageLock = {};
|
|
20
24
|
routesAlias.set(handler.router.customRoutes);
|
|
21
25
|
const basename = handler.router.basename;
|
|
22
26
|
const routes = handler.routes.map(route => {
|
|
@@ -38,29 +42,35 @@ function createRouter(history, app, config, framework) {
|
|
|
38
42
|
eventCenter.trigger('__taroRouterLaunch', launchParam);
|
|
39
43
|
(_a = app.onLaunch) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
|
|
40
44
|
app.onError && window.addEventListener('error', e => { var _a; return (_a = app.onError) === null || _a === void 0 ? void 0 : _a.call(app, e.message); });
|
|
41
|
-
const render = (
|
|
42
|
-
var
|
|
43
|
-
|
|
44
|
-
|
|
45
|
+
const render = (_c) => __awaiter(this, [_c], void 0, function* ({ location, action }) {
|
|
46
|
+
var _d, _e, _f, _g, _h, _j, _k, _l;
|
|
47
|
+
// Note: 由于下面有异步加载操作 先不要在这里去设置 handler.pathname
|
|
48
|
+
const currentPathname = decodeURI(location.pathname);
|
|
49
|
+
if ((_d = window.__taroAppConfig) === null || _d === void 0 ? void 0 : _d.usingWindowScroll)
|
|
45
50
|
window.scrollTo(0, 0);
|
|
46
51
|
eventCenter.trigger('__taroRouterChange', {
|
|
47
52
|
toLocation: {
|
|
48
|
-
path:
|
|
53
|
+
path: currentPathname
|
|
49
54
|
}
|
|
50
55
|
});
|
|
51
|
-
let element, params;
|
|
56
|
+
let element, context, params;
|
|
57
|
+
const routerPath = handler.router.forcePath || currentPathname;
|
|
58
|
+
pageLock[routerPath] = typeof pageLock[routerPath] === 'number' ? pageLock[routerPath] + 1 : 1;
|
|
59
|
+
const currentLock = pageLock[routerPath];
|
|
60
|
+
let postLock;
|
|
52
61
|
try {
|
|
53
|
-
const result = yield router.resolve(
|
|
54
|
-
[element, , params] = yield Promise.all(result);
|
|
62
|
+
const result = yield router.resolve(routerPath);
|
|
63
|
+
[element, context, params] = yield Promise.all(result);
|
|
64
|
+
postLock = pageLock[routerPath];
|
|
55
65
|
}
|
|
56
66
|
catch (error) {
|
|
57
67
|
if (error.status === 404) {
|
|
58
68
|
const notFoundEvent = {
|
|
59
69
|
isEntryPage: stacks.length === 0,
|
|
60
|
-
path:
|
|
70
|
+
path: currentPathname,
|
|
61
71
|
query: handler.getQuery(createStampId()),
|
|
62
72
|
};
|
|
63
|
-
(
|
|
73
|
+
(_e = app.onPageNotFound) === null || _e === void 0 ? void 0 : _e.call(app, notFoundEvent);
|
|
64
74
|
eventCenter.trigger('__taroRouterNotFound', notFoundEvent);
|
|
65
75
|
}
|
|
66
76
|
else if (/Loading hot update .* failed./.test(error.message)) {
|
|
@@ -71,13 +81,16 @@ function createRouter(history, app, config, framework) {
|
|
|
71
81
|
throw error;
|
|
72
82
|
}
|
|
73
83
|
}
|
|
74
|
-
if (!element)
|
|
84
|
+
if (!element || currentLock !== postLock)
|
|
75
85
|
return;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
let
|
|
86
|
+
// Note: 异步结束后,在设置 handler.pathname
|
|
87
|
+
// context.pathname 在 universal-router 被处理过了,是发起资源请求的时候传入的 pathname,即 await router.resolve(routerPath) 这个 routerPath
|
|
88
|
+
handler.pathname = context.pathname;
|
|
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';
|
|
81
94
|
if (pageConfig) {
|
|
82
95
|
if (typeof pageConfig.enablePullDownRefresh === 'boolean') {
|
|
83
96
|
enablePullDownRefresh = pageConfig.enablePullDownRefresh;
|
|
@@ -94,8 +107,7 @@ function createRouter(history, app, config, framework) {
|
|
|
94
107
|
}
|
|
95
108
|
eventCenter.trigger('__taroSetNavigationStyle', navigationStyle, navigationBarTextStyle, navigationBarBackgroundColor);
|
|
96
109
|
const currentPage = Current.page;
|
|
97
|
-
const
|
|
98
|
-
const methodName = (_j = stacks.method) !== null && _j !== void 0 ? _j : '';
|
|
110
|
+
const methodName = (_k = stacks.method) !== null && _k !== void 0 ? _k : '';
|
|
99
111
|
const cacheTabs = stacks.getTabs();
|
|
100
112
|
let shouldLoad = false;
|
|
101
113
|
stacks.method = '';
|
|
@@ -110,10 +122,11 @@ function createRouter(history, app, config, framework) {
|
|
|
110
122
|
}
|
|
111
123
|
shouldLoad = true;
|
|
112
124
|
}
|
|
113
|
-
else if (currentPage && handler.isTabBar(
|
|
125
|
+
else if (currentPage && handler.isTabBar(pathname)) {
|
|
114
126
|
if (handler.isSamePage(currentPage))
|
|
115
127
|
return;
|
|
116
128
|
if (handler.isTabBar(currentPage.path)) {
|
|
129
|
+
// NOTE: 从 tabBar 页面切换到 tabBar 页面
|
|
117
130
|
handler.hide(currentPage);
|
|
118
131
|
stacks.pushTab(currentPage.path.split('?')[0]);
|
|
119
132
|
}
|
|
@@ -127,8 +140,8 @@ function createRouter(history, app, config, framework) {
|
|
|
127
140
|
handler.unload(currentPage, stacks.length, true);
|
|
128
141
|
}
|
|
129
142
|
}
|
|
130
|
-
if (cacheTabs[
|
|
131
|
-
stacks.popTab(
|
|
143
|
+
if (cacheTabs[pathname]) {
|
|
144
|
+
stacks.popTab(pathname);
|
|
132
145
|
return handler.show(stacks.getItem(0), pageConfig, 0);
|
|
133
146
|
}
|
|
134
147
|
shouldLoad = true;
|
|
@@ -157,11 +170,11 @@ function createRouter(history, app, config, framework) {
|
|
|
157
170
|
shouldLoad = true;
|
|
158
171
|
}
|
|
159
172
|
else if (action === 'PUSH') {
|
|
160
|
-
handler.hide(currentPage);
|
|
173
|
+
handler.hide(currentPage, true);
|
|
161
174
|
shouldLoad = true;
|
|
162
175
|
}
|
|
163
176
|
if (shouldLoad || stacks.length < 1) {
|
|
164
|
-
const el = (
|
|
177
|
+
const el = (_l = element.default) !== null && _l !== void 0 ? _l : element;
|
|
165
178
|
const loadConfig = Object.assign({}, pageConfig);
|
|
166
179
|
const stacksIndex = stacks.length;
|
|
167
180
|
delete loadConfig['path'];
|
|
@@ -187,12 +200,23 @@ function createRouter(history, app, config, framework) {
|
|
|
187
200
|
render({ location: history.location, action: Action.Push });
|
|
188
201
|
(_b = app.onShow) === null || _b === void 0 ? void 0 : _b.call(app, launchParam);
|
|
189
202
|
window.addEventListener('visibilitychange', () => {
|
|
190
|
-
var _a, _b;
|
|
203
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
204
|
+
const currentPath = ((_a = Current.page) === null || _a === void 0 ? void 0 : _a.path) || '';
|
|
205
|
+
const path = currentPath.substring(0, currentPath.indexOf('?'));
|
|
206
|
+
const param = {};
|
|
207
|
+
// app的 onShow/onHide 生命周期的路径信息为当前页面的路径
|
|
208
|
+
Object.assign(param, launchParam, { path });
|
|
191
209
|
if (document.visibilityState === 'visible') {
|
|
192
|
-
(
|
|
210
|
+
(_b = app.onShow) === null || _b === void 0 ? void 0 : _b.call(app, param);
|
|
211
|
+
// 单页面app显示后一刻会触发当前 page.onShow 生命周期函数
|
|
212
|
+
(_d = (_c = Current.page) === null || _c === void 0 ? void 0 : _c.onShow) === null || _d === void 0 ? void 0 : _d.call(_c);
|
|
193
213
|
}
|
|
194
214
|
else {
|
|
195
|
-
|
|
215
|
+
// 单页面app隐藏前一刻会触发当前 page.onHide 生命周期函数
|
|
216
|
+
if ((_e = Current.page) === null || _e === void 0 ? void 0 : _e.path) {
|
|
217
|
+
safeExecute((_f = Current.page) === null || _f === void 0 ? void 0 : _f.path, 'onHide');
|
|
218
|
+
}
|
|
219
|
+
(_g = app.onHide) === null || _g === void 0 ? void 0 : _g.call(app, param);
|
|
196
220
|
}
|
|
197
221
|
});
|
|
198
222
|
return history.listen(render);
|
package/dist/router/stack.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PageInstance } from '@tarojs/runtime';
|
|
1
|
+
import type { 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
|
|
26
|
+
export default stacks;
|
package/dist/style.d.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 插入页面动画需要的样式
|
|
3
3
|
*/
|
|
4
|
-
declare function loadAnimateStyle(ms?: number): void;
|
|
4
|
+
export declare function loadAnimateStyle(ms?: number): void;
|
|
5
5
|
/**
|
|
6
6
|
* 插入路由相关样式
|
|
7
7
|
*/
|
|
8
|
-
declare function loadRouterStyle(enableTabBar: boolean, enableWindowScroll: boolean): void;
|
|
8
|
+
export declare function loadRouterStyle(enableTabBar: boolean, enableWindowScroll: boolean): void;
|
|
9
9
|
/**
|
|
10
10
|
* 插入导航栏相关的样式
|
|
11
11
|
*/
|
|
12
|
-
declare function loadNavigationBarStyle(): void;
|
|
13
|
-
declare function addStyle(css: any): void;
|
|
14
|
-
export { loadAnimateStyle, loadRouterStyle, loadNavigationBarStyle, addStyle };
|
|
12
|
+
export declare function loadNavigationBarStyle(): void;
|
|
13
|
+
export declare function addStyle(css: any): void;
|
package/dist/style.js
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
function loadAnimateStyle(ms = 300) {
|
|
5
5
|
const css = `
|
|
6
6
|
body {
|
|
7
|
-
|
|
7
|
+
/* 防止 iOS 页面滚动 */
|
|
8
|
+
overflow: hidden;
|
|
8
9
|
}
|
|
9
10
|
.taro_router > .taro_page {
|
|
10
11
|
position: absolute;
|
|
@@ -21,6 +22,7 @@ body {
|
|
|
21
22
|
.taro_router > .taro_page.taro_tabbar_page,
|
|
22
23
|
.taro_router > .taro_page.taro_page_show.taro_page_stationed {
|
|
23
24
|
transform: none;
|
|
25
|
+
transition: none;
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
.taro_router > .taro_page.taro_page_show {
|
|
@@ -60,8 +62,9 @@ ${enableTabBar ? `
|
|
|
60
62
|
}
|
|
61
63
|
|
|
62
64
|
` : ''}
|
|
63
|
-
.taro_page_shade,
|
|
64
|
-
.
|
|
65
|
+
.taro_page_shade:has(+.taro_page_stationed),
|
|
66
|
+
.taro_page_shade.taro_tabbar_page,
|
|
67
|
+
.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) {
|
|
65
68
|
display: none;
|
|
66
69
|
}
|
|
67
70
|
`;
|
|
@@ -73,13 +76,13 @@ ${enableTabBar ? `
|
|
|
73
76
|
function loadNavigationBarStyle() {
|
|
74
77
|
const css = `
|
|
75
78
|
.taro-navigation-bar-show {
|
|
79
|
+
display: flex;
|
|
76
80
|
background: white;
|
|
77
81
|
position: sticky;
|
|
78
82
|
z-index: 500;
|
|
79
83
|
top: 0;
|
|
80
84
|
padding-bottom: 8px;
|
|
81
85
|
padding-top: calc(env(safe-area-inset-top) + 8px);
|
|
82
|
-
display: flex;
|
|
83
86
|
justify-content: center;
|
|
84
87
|
align-items: center;
|
|
85
88
|
}
|
|
@@ -88,37 +91,73 @@ function loadNavigationBarStyle() {
|
|
|
88
91
|
display: none;
|
|
89
92
|
}
|
|
90
93
|
|
|
91
|
-
taro-navigation-bar-title {
|
|
94
|
+
.taro-navigation-bar-title-wrap {
|
|
95
|
+
display: flex;
|
|
96
|
+
height: 24px;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.taro-navigation-bar-title-wrap > .taro-navigation-bar-loading {
|
|
100
|
+
display: none;
|
|
101
|
+
animation: loading 2s linear infinite;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
.taro-navigation-bar-title-wrap .taro-navigation-bar-loading.taro-navigation-bar-loading-show {
|
|
105
|
+
display: flex;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.taro-navigation-bar-title-wrap > .taro-navigation-bar-title {
|
|
92
109
|
font-size: 24px;
|
|
93
110
|
height: 24px;
|
|
94
111
|
line-height: 24px;
|
|
112
|
+
max-width: 100px;
|
|
113
|
+
white-space: nowrap;
|
|
114
|
+
overflow: hidden;
|
|
115
|
+
line-height: 24px;
|
|
116
|
+
text-overflow: ellipsis;
|
|
95
117
|
}
|
|
96
118
|
|
|
97
|
-
|
|
119
|
+
@keyframes loading {
|
|
120
|
+
from {
|
|
121
|
+
transform: rotate(0deg);
|
|
122
|
+
}
|
|
123
|
+
to {
|
|
124
|
+
transform: rotate(360deg);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
@keyframes loading {
|
|
129
|
+
from {
|
|
130
|
+
transform: rotate(0deg);
|
|
131
|
+
}
|
|
132
|
+
to {
|
|
133
|
+
transform: rotate(360deg);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.taro-navigation-bar-no-icon > .taro-navigation-bar-home {
|
|
98
138
|
display: none;
|
|
99
139
|
}
|
|
100
140
|
|
|
101
|
-
.taro-navigation-bar-no-icon > taro-navigation-bar-back {
|
|
141
|
+
.taro-navigation-bar-no-icon > .taro-navigation-bar-back {
|
|
102
142
|
display: none;
|
|
103
143
|
}
|
|
104
144
|
|
|
105
|
-
.taro-navigation-bar-home > taro-navigation-bar-home {
|
|
106
|
-
display:
|
|
145
|
+
.taro-navigation-bar-home-icon > .taro-navigation-bar-home {
|
|
146
|
+
display: flex;
|
|
107
147
|
left: 8px;
|
|
108
148
|
position: absolute;
|
|
109
149
|
width: 24px;
|
|
110
150
|
height: 24px;
|
|
111
151
|
}
|
|
112
152
|
|
|
113
|
-
.taro-navigation-bar-back > taro-navigation-bar-back {
|
|
114
|
-
display:
|
|
153
|
+
.taro-navigation-bar-back-icon > .taro-navigation-bar-back {
|
|
154
|
+
display: flex;
|
|
115
155
|
left: 8px;
|
|
116
156
|
position: absolute;
|
|
117
157
|
width: 24px;
|
|
118
158
|
height: 24px;
|
|
119
159
|
}
|
|
120
|
-
|
|
121
|
-
`;
|
|
160
|
+
`;
|
|
122
161
|
addStyle(css);
|
|
123
162
|
}
|
|
124
163
|
function addStyle(css) {
|
package/dist/tabbar.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import { AppConfig } from '@tarojs/taro';
|
|
2
|
-
import { History } from
|
|
3
|
-
declare function initTabbar(config: AppConfig, history: History): void;
|
|
4
|
-
export { initTabbar };
|
|
2
|
+
import type { History } from 'history';
|
|
3
|
+
export declare function initTabbar(config: AppConfig, history: History): void;
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -6,6 +6,5 @@ declare class RoutesAlias {
|
|
|
6
6
|
getAlias: (url?: string) => string;
|
|
7
7
|
getAll: (url?: string) => string[];
|
|
8
8
|
}
|
|
9
|
-
declare const routesAlias: RoutesAlias;
|
|
10
|
-
export
|
|
11
|
-
export * from "./navigate.js";
|
|
9
|
+
export declare const routesAlias: RoutesAlias;
|
|
10
|
+
export * from './navigate';
|
package/dist/utils/navigate.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
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: {
|
|
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: {
|
|
6
6
|
backgroundColor: string;
|
|
7
7
|
frontColor: string;
|
|
8
8
|
}): void;
|
|
9
|
-
export
|
|
9
|
+
export declare function setNavigationBarLoading(loading: boolean): void;
|
package/dist/utils/navigate.js
CHANGED
|
@@ -19,10 +19,13 @@ function setMpaTitle(title) {
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
function setTitle(title) {
|
|
22
|
-
eventCenter.trigger('
|
|
22
|
+
eventCenter.trigger('__taroH5SetNavigationBarTitle', title);
|
|
23
23
|
}
|
|
24
24
|
function setNavigationBarStyle(option) {
|
|
25
25
|
eventCenter.trigger('__taroH5setNavigationBarColor', option);
|
|
26
26
|
}
|
|
27
|
+
function setNavigationBarLoading(loading) {
|
|
28
|
+
eventCenter.trigger('__taroH5setNavigationBarLoading', loading);
|
|
29
|
+
}
|
|
27
30
|
|
|
28
|
-
export { isDingTalk, isWeixin, setMpaTitle, setNavigationBarStyle, setTitle };
|
|
31
|
+
export { isDingTalk, isWeixin, setMpaTitle, setNavigationBarLoading, setNavigationBarStyle, setTitle };
|
package/package.json
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tarojs/router",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.21",
|
|
4
4
|
"description": "Taro-router",
|
|
5
|
+
"author": "O2Team",
|
|
6
|
+
"license": "MIT",
|
|
5
7
|
"browser": "dist/index.js",
|
|
6
8
|
"main:h5": "dist/index.esm.js",
|
|
7
9
|
"main": "dist/index.js",
|
|
@@ -20,45 +22,34 @@
|
|
|
20
22
|
"keywords": [
|
|
21
23
|
"router"
|
|
22
24
|
],
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">= 18"
|
|
27
|
+
},
|
|
25
28
|
"dependencies": {
|
|
26
29
|
"dingtalk-jsapi": "~2.15.2",
|
|
27
|
-
"history": "^5.
|
|
30
|
+
"history": "^5.3.0",
|
|
28
31
|
"mobile-detect": "^1.4.2",
|
|
29
|
-
"query-string": "^
|
|
32
|
+
"query-string": "^9.0.0",
|
|
30
33
|
"tslib": "^2.6.2",
|
|
31
|
-
"universal-router": "^
|
|
34
|
+
"universal-router": "^9.2.0"
|
|
32
35
|
},
|
|
33
36
|
"devDependencies": {
|
|
34
|
-
"@
|
|
35
|
-
"@
|
|
36
|
-
"@
|
|
37
|
-
"@
|
|
38
|
-
"jest": "^29.3.1",
|
|
39
|
-
"jest-cli": "^29.3.1",
|
|
40
|
-
"jest-environment-jsdom": "^29.6.4",
|
|
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/runtime": "4.0.0-alpha.2",
|
|
48
|
-
"@tarojs/taro": "4.0.0-alpha.2"
|
|
37
|
+
"@tarojs/runtime": "4.0.0-alpha.21",
|
|
38
|
+
"@tarojs/components": "4.0.0-alpha.21",
|
|
39
|
+
"@tarojs/shared": "4.0.0-alpha.21",
|
|
40
|
+
"@tarojs/taro": "4.0.0-alpha.21"
|
|
49
41
|
},
|
|
50
42
|
"peerDependencies": {
|
|
51
|
-
"@tarojs/
|
|
52
|
-
"@tarojs/
|
|
43
|
+
"@tarojs/taro": "4.0.0-alpha.21",
|
|
44
|
+
"@tarojs/shared": "4.0.0-alpha.21",
|
|
45
|
+
"@tarojs/runtime": "4.0.0-alpha.21"
|
|
53
46
|
},
|
|
54
47
|
"scripts": {
|
|
48
|
+
"prod": "pnpm run build",
|
|
55
49
|
"prebuild": "pnpm run clean",
|
|
56
50
|
"build": "pnpm run rollup --environment NODE_ENV:production",
|
|
57
51
|
"clean": "rimraf --impl=move-remove ./dist",
|
|
58
52
|
"dev": "pnpm run rollup --environment NODE_ENV:development -w",
|
|
59
|
-
"rollup": "rollup --config rollup.config.
|
|
60
|
-
"test": "cross-env NODE_ENV=jest jest",
|
|
61
|
-
"test:ci": "cross-env NODE_ENV=jest jest --ci -i --coverage --silent",
|
|
62
|
-
"test:dev": "cross-env NODE_ENV=jest jest --watch"
|
|
53
|
+
"rollup": "rollup --config rollup.config.mts --configPlugin typescript"
|
|
63
54
|
}
|
|
64
55
|
}
|
package/types/api.d.ts
CHANGED
package/dist/index.cjs.d.ts
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
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 handleAppMount(config: SpaRouterConfig | MpaRouterConfig, _: History, appId?: string): void;
|
|
64
|
-
declare function handleAppMountWithTabbar(config: SpaRouterConfig | MpaRouterConfig, history: History, appId?: string): void;
|
|
65
|
-
export { navigateTo, redirectTo, navigateBack, switchTab, reLaunch, getCurrentPages, history, setHistory, createMpaHistory, createBrowserHistory, createHashHistory, setHistoryMode, prependBasename, createMultiRouter, createRouter, routesAlias, isWeixin, isDingTalk, setMpaTitle, setTitle, setNavigationBarStyle, handleAppMount, handleAppMountWithTabbar };
|
package/dist/index.esm.d.ts
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
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 handleAppMount(config: SpaRouterConfig | MpaRouterConfig, _: History, appId?: string): void;
|
|
64
|
-
declare function handleAppMountWithTabbar(config: SpaRouterConfig | MpaRouterConfig, history: History, appId?: string): void;
|
|
65
|
-
export { navigateTo, redirectTo, navigateBack, switchTab, reLaunch, getCurrentPages, history, setHistory, createMpaHistory, createBrowserHistory, createHashHistory, setHistoryMode, prependBasename, createMultiRouter, createRouter, routesAlias, isWeixin, isDingTalk, setMpaTitle, setTitle, setNavigationBarStyle, handleAppMount, handleAppMountWithTabbar };
|