@tarojs/router 3.6.22 → 3.6.23
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 +14 -0
- package/dist/api.d.ts +7 -6
- package/dist/api.js +15 -19
- package/dist/events/resize.d.ts +2 -1
- package/dist/events/resize.js +3 -1
- package/dist/events/scroll.d.ts +2 -1
- package/dist/events/scroll.js +4 -1
- package/dist/history.d.ts +24 -5
- package/dist/history.js +17 -6
- package/dist/index.cjs.d.ts +44 -6
- package/dist/index.cjs.js +201 -239
- package/dist/index.d.ts +10 -4
- package/dist/index.esm.d.ts +44 -6
- package/dist/index.esm.js +162 -210
- package/dist/index.js +49 -4
- package/dist/router/index.d.ts +4 -3
- package/dist/router/index.js +5 -2
- package/dist/router/mpa.d.ts +5 -3
- package/dist/router/mpa.js +10 -16
- package/dist/router/multi-page.d.ts +9 -6
- package/dist/router/multi-page.js +15 -42
- package/dist/router/page.d.ts +9 -6
- package/dist/router/page.js +17 -43
- package/dist/router/spa.d.ts +5 -3
- package/dist/router/spa.js +15 -21
- package/dist/router/stack.d.ts +1 -1
- package/dist/router/stack.js +2 -1
- package/dist/style.d.ts +4 -3
- package/dist/style.js +12 -6
- package/dist/tabbar.d.ts +3 -1
- package/dist/tabbar.js +4 -3
- package/dist/utils/index.d.ts +3 -9
- package/dist/utils/index.js +6 -20
- package/dist/utils/navigate.d.ts +4 -3
- package/dist/utils/navigate.js +7 -12
- package/package.json +24 -14
- package/types/component.d.ts +5 -0
- package/types/taro.d.ts +8 -0
- package/dist/index.cjs.js.map +0 -1
- package/dist/index.esm.js.map +0 -1
package/dist/index.esm.d.ts
CHANGED
|
@@ -1,14 +1,38 @@
|
|
|
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';
|
|
1
5
|
import Taro from "@tarojs/taro";
|
|
2
|
-
import { History } from "history";
|
|
3
6
|
import { AppInstance } from "@tarojs/runtime";
|
|
4
|
-
import { MpaRouterConfig
|
|
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;
|
|
5
30
|
declare function navigateTo(option: Taro.navigateTo.Option): ReturnType<typeof Taro.navigateTo>;
|
|
6
31
|
declare function redirectTo(option: Taro.redirectTo.Option): ReturnType<typeof Taro.redirectTo>;
|
|
7
32
|
declare function navigateBack(option?: Taro.navigateBack.Option): ReturnType<typeof Taro.navigateBack>;
|
|
8
33
|
declare function switchTab(option: Taro.switchTab.Option): ReturnType<typeof Taro.switchTab>;
|
|
9
34
|
declare function reLaunch(option: Taro.reLaunch.Option): ReturnType<typeof Taro.reLaunch>;
|
|
10
35
|
declare function getCurrentPages(): Taro.Page[];
|
|
11
|
-
declare let history: History;
|
|
12
36
|
// TODO 支持多路由 (APP 生命周期仅触发一次)
|
|
13
37
|
/** Note: 关于多页面应用
|
|
14
38
|
* - 需要配置路由映射(根目录跳转、404 页面……)
|
|
@@ -17,6 +41,20 @@ declare let history: History;
|
|
|
17
41
|
* - TabBar 会多次加载
|
|
18
42
|
* - 不支持路由动画
|
|
19
43
|
*/
|
|
20
|
-
declare function createMultiRouter(app: AppInstance, config: MpaRouterConfig, framework?: string): Promise<void>;
|
|
21
|
-
declare function createRouter(app: AppInstance, config: SpaRouterConfig, framework?: string): () => void;
|
|
22
|
-
|
|
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 setTitle(title: string): Promise<string>;
|
|
58
|
+
declare function handleAppMount(config: SpaRouterConfig | MpaRouterConfig, _: History, appId?: string): void;
|
|
59
|
+
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 };
|
package/dist/index.esm.js
CHANGED
|
@@ -1,93 +1,39 @@
|
|
|
1
|
-
import { createBrowserHistory, createHashHistory, Action, parsePath } from 'history';
|
|
2
|
-
import { Current, incrementId, eventCenter, createPageConfig, hooks, stringify, requestAnimationFrame as requestAnimationFrame$1 } from '@tarojs/runtime';
|
|
3
|
-
import queryString from 'query-string';
|
|
4
1
|
import { defineCustomElementTaroTabbar } from '@tarojs/components/dist/components';
|
|
5
2
|
import { initTabBarApis } from '@tarojs/taro';
|
|
3
|
+
import { __awaiter } from 'tslib';
|
|
4
|
+
import { addLeadingSlash, Current, stripBasename, incrementId, eventCenter, createPageConfig, hooks, stringify, getHomePage, getCurrentPage, stripTrailing, requestAnimationFrame as requestAnimationFrame$1 } from '@tarojs/runtime';
|
|
5
|
+
import { createBrowserHistory, createHashHistory, Action, parsePath } from 'history';
|
|
6
|
+
export { createBrowserHistory, createHashHistory } from 'history';
|
|
7
|
+
import queryString from 'query-string';
|
|
6
8
|
import UniversalRouter from 'universal-router';
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
12
|
-
purpose with or without fee is hereby granted.
|
|
13
|
-
|
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
15
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
16
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
17
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
18
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
19
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
20
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
21
|
-
***************************************************************************** */
|
|
22
|
-
|
|
23
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
24
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
25
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
26
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
27
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
28
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
29
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// export const removeLeadingSlash = (str = '') => str.replace(/^\.?\//, '')
|
|
34
|
-
// export const removeTrailingSearch = (str = '') => str.replace(/\?[\s\S]*$/, '')
|
|
35
|
-
const addLeadingSlash = (url = '') => (url.charAt(0) === '/' ? url : '/' + url);
|
|
36
|
-
const hasBasename = (path = '', prefix = '') => new RegExp('^' + prefix + '(\\/|\\?|#|$)', 'i').test(path) || path === prefix;
|
|
37
|
-
const stripBasename = (path = '', prefix = '') => hasBasename(path, prefix) ? path.substring(prefix.length) : path;
|
|
38
|
-
const stripTrailing = (str = '') => str.replace(/[?#][\s\S]*$/, '');
|
|
39
|
-
const getHomePage = (path = '', basename = '', customRoutes = {}, entryPagePath = '') => {
|
|
40
|
-
var _a;
|
|
41
|
-
const routePath = addLeadingSlash(stripBasename(path, basename));
|
|
42
|
-
const alias = ((_a = Object.entries(customRoutes).find(([key]) => key === routePath)) === null || _a === void 0 ? void 0 : _a[1]) || routePath;
|
|
43
|
-
return entryPagePath || (typeof alias === 'string' ? alias : alias[0]) || basename;
|
|
44
|
-
};
|
|
45
|
-
const getCurrentPage = (routerMode = 'hash', basename = '/') => {
|
|
46
|
-
const pagePath = routerMode === 'hash'
|
|
47
|
-
? location.hash.slice(1).split('?')[0]
|
|
48
|
-
: location.pathname;
|
|
49
|
-
return addLeadingSlash(stripBasename(pagePath, basename));
|
|
50
|
-
};
|
|
51
|
-
class RoutesAlias {
|
|
52
|
-
constructor() {
|
|
53
|
-
this.conf = [];
|
|
54
|
-
this.getConfig = (url = '') => {
|
|
55
|
-
const customRoute = this.conf.filter((arr) => {
|
|
56
|
-
return arr.includes(url);
|
|
57
|
-
});
|
|
58
|
-
return customRoute[0];
|
|
59
|
-
};
|
|
60
|
-
this.getOrigin = (url = '') => {
|
|
61
|
-
var _a;
|
|
62
|
-
return ((_a = this.getConfig(url)) === null || _a === void 0 ? void 0 : _a[0]) || url;
|
|
63
|
-
};
|
|
64
|
-
this.getAlias = (url = '') => {
|
|
65
|
-
var _a;
|
|
66
|
-
return ((_a = this.getConfig(url)) === null || _a === void 0 ? void 0 : _a[1]) || url;
|
|
67
|
-
};
|
|
68
|
-
this.getAll = (url = '') => {
|
|
69
|
-
return this.conf
|
|
70
|
-
.filter((arr) => arr.includes(url))
|
|
71
|
-
.reduceRight((p, a) => {
|
|
72
|
-
p.unshift(a[1]);
|
|
73
|
-
return p;
|
|
74
|
-
}, []);
|
|
75
|
-
};
|
|
10
|
+
function initTabbar(config, history) {
|
|
11
|
+
if (config.tabBar == null) {
|
|
12
|
+
return;
|
|
76
13
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
14
|
+
// TODO: custom-tab-bar
|
|
15
|
+
defineCustomElementTaroTabbar();
|
|
16
|
+
const tabbar = document.createElement('taro-tabbar');
|
|
17
|
+
const homePage = config.entryPagePath || (config.pages ? config.pages[0] : '');
|
|
18
|
+
tabbar.conf = config.tabBar;
|
|
19
|
+
tabbar.conf.homePage = history.location.pathname === '/' ? homePage : history.location.pathname;
|
|
20
|
+
const routerConfig = config.router;
|
|
21
|
+
tabbar.conf.mode = routerConfig && routerConfig.mode ? routerConfig.mode : 'hash';
|
|
22
|
+
if (routerConfig.customRoutes) {
|
|
23
|
+
tabbar.conf.custom = true;
|
|
24
|
+
tabbar.conf.customRoutes = routerConfig.customRoutes;
|
|
88
25
|
}
|
|
26
|
+
else {
|
|
27
|
+
tabbar.conf.custom = false;
|
|
28
|
+
tabbar.conf.customRoutes = {};
|
|
29
|
+
}
|
|
30
|
+
if (typeof routerConfig.basename !== 'undefined') {
|
|
31
|
+
tabbar.conf.basename = routerConfig.basename;
|
|
32
|
+
}
|
|
33
|
+
const container = document.getElementById('container');
|
|
34
|
+
container === null || container === void 0 ? void 0 : container.appendChild(tabbar);
|
|
35
|
+
initTabBarApis(config);
|
|
89
36
|
}
|
|
90
|
-
const routesAlias = new RoutesAlias();
|
|
91
37
|
|
|
92
38
|
class RouterConfig {
|
|
93
39
|
static set config(e) {
|
|
@@ -190,6 +136,13 @@ class MpaHistory {
|
|
|
190
136
|
};
|
|
191
137
|
}
|
|
192
138
|
}
|
|
139
|
+
function setHistory(h, base = '/') {
|
|
140
|
+
history = h;
|
|
141
|
+
basename = base;
|
|
142
|
+
}
|
|
143
|
+
function createMpaHistory(_) {
|
|
144
|
+
return new MpaHistory();
|
|
145
|
+
}
|
|
193
146
|
function setHistoryMode(mode, base = '/') {
|
|
194
147
|
const options = {
|
|
195
148
|
window
|
|
@@ -199,7 +152,7 @@ function setHistoryMode(mode, base = '/') {
|
|
|
199
152
|
history = createBrowserHistory(options);
|
|
200
153
|
}
|
|
201
154
|
else if (mode === 'multi') {
|
|
202
|
-
history =
|
|
155
|
+
history = createMpaHistory();
|
|
203
156
|
}
|
|
204
157
|
else {
|
|
205
158
|
// default is hash
|
|
@@ -291,6 +244,69 @@ class Stacks {
|
|
|
291
244
|
}
|
|
292
245
|
const stacks = new Stacks();
|
|
293
246
|
|
|
247
|
+
let preTitle = document.title;
|
|
248
|
+
let isLoadDdEntry = false;
|
|
249
|
+
const isWeixin = () => !!navigator.userAgent.match(/\bMicroMessenger\b/ig);
|
|
250
|
+
const isDingTalk = () => !!navigator.userAgent.match(/\bDingTalk\b/ig);
|
|
251
|
+
function setTitle(title) {
|
|
252
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
253
|
+
if (preTitle === title)
|
|
254
|
+
return title;
|
|
255
|
+
document.title = title;
|
|
256
|
+
preTitle = title;
|
|
257
|
+
if (process.env.SUPPORT_DINGTALK_NAVIGATE !== 'disabled' && isDingTalk()) {
|
|
258
|
+
if (!isLoadDdEntry) {
|
|
259
|
+
isLoadDdEntry = true;
|
|
260
|
+
require('dingtalk-jsapi/platform');
|
|
261
|
+
}
|
|
262
|
+
const setDingTitle = require('dingtalk-jsapi/api/biz/navigation/setTitle').default;
|
|
263
|
+
setDingTitle({ title });
|
|
264
|
+
}
|
|
265
|
+
return title;
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
class RoutesAlias {
|
|
270
|
+
constructor() {
|
|
271
|
+
this.conf = [];
|
|
272
|
+
this.getConfig = (url = '') => {
|
|
273
|
+
const customRoute = this.conf.filter((arr) => {
|
|
274
|
+
return arr.includes(url);
|
|
275
|
+
});
|
|
276
|
+
return customRoute[0];
|
|
277
|
+
};
|
|
278
|
+
this.getOrigin = (url = '') => {
|
|
279
|
+
var _a;
|
|
280
|
+
return ((_a = this.getConfig(url)) === null || _a === void 0 ? void 0 : _a[0]) || url;
|
|
281
|
+
};
|
|
282
|
+
this.getAlias = (url = '') => {
|
|
283
|
+
var _a;
|
|
284
|
+
return ((_a = this.getConfig(url)) === null || _a === void 0 ? void 0 : _a[1]) || url;
|
|
285
|
+
};
|
|
286
|
+
this.getAll = (url = '') => {
|
|
287
|
+
return this.conf
|
|
288
|
+
.filter((arr) => arr.includes(url))
|
|
289
|
+
.reduceRight((p, a) => {
|
|
290
|
+
p.unshift(a[1]);
|
|
291
|
+
return p;
|
|
292
|
+
}, []);
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
set(customRoutes = {}) {
|
|
296
|
+
for (let key in customRoutes) {
|
|
297
|
+
const path = customRoutes[key];
|
|
298
|
+
key = addLeadingSlash(key);
|
|
299
|
+
if (typeof path === 'string') {
|
|
300
|
+
this.conf.push([key, addLeadingSlash(path)]);
|
|
301
|
+
}
|
|
302
|
+
else if ((path === null || path === void 0 ? void 0 : path.length) > 0) {
|
|
303
|
+
this.conf.push(...path.map(p => [key, addLeadingSlash(p)]));
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
const routesAlias = new RoutesAlias();
|
|
309
|
+
|
|
294
310
|
function processNavigateUrl(option) {
|
|
295
311
|
var _a;
|
|
296
312
|
const pathPieces = parsePath(option.url);
|
|
@@ -387,27 +403,6 @@ function getCurrentPages() {
|
|
|
387
403
|
return pages.map(e => { var _a; return (Object.assign(Object.assign({}, e), { route: ((_a = e.path) === null || _a === void 0 ? void 0 : _a.replace(/\?.*/g, '')) || '' })); });
|
|
388
404
|
}
|
|
389
405
|
|
|
390
|
-
let preTitle = document.title;
|
|
391
|
-
let isLoadDdEntry = false;
|
|
392
|
-
const isDingTalk = () => !!navigator.userAgent.match(/\bDingTalk\b/ig);
|
|
393
|
-
function setTitle(title) {
|
|
394
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
395
|
-
if (preTitle === title)
|
|
396
|
-
return title;
|
|
397
|
-
document.title = title;
|
|
398
|
-
preTitle = title;
|
|
399
|
-
if (process.env.SUPPORT_DINGTALK_NAVIGATE !== 'disabled' && isDingTalk()) {
|
|
400
|
-
if (!isLoadDdEntry) {
|
|
401
|
-
isLoadDdEntry = true;
|
|
402
|
-
require('dingtalk-jsapi/platform');
|
|
403
|
-
}
|
|
404
|
-
const setDingTitle = require('dingtalk-jsapi/api/biz/navigation/setTitle').default;
|
|
405
|
-
setDingTitle({ title });
|
|
406
|
-
}
|
|
407
|
-
return title;
|
|
408
|
-
});
|
|
409
|
-
}
|
|
410
|
-
|
|
411
406
|
let pageResizeFn;
|
|
412
407
|
function bindPageResize(page) {
|
|
413
408
|
pageResizeFn && window.removeEventListener('resize', pageResizeFn);
|
|
@@ -461,6 +456,9 @@ function getOffset() {
|
|
|
461
456
|
*/
|
|
462
457
|
function loadAnimateStyle(ms = 300) {
|
|
463
458
|
const css = `
|
|
459
|
+
body {
|
|
460
|
+
overflow: hidden; // 防止 iOS 页面滚动
|
|
461
|
+
}
|
|
464
462
|
.taro_router > .taro_page {
|
|
465
463
|
position: absolute;
|
|
466
464
|
left: 0;
|
|
@@ -487,7 +485,7 @@ function loadAnimateStyle(ms = 300) {
|
|
|
487
485
|
/**
|
|
488
486
|
* 插入路由相关样式
|
|
489
487
|
*/
|
|
490
|
-
function loadRouterStyle(
|
|
488
|
+
function loadRouterStyle(enableTabBar, enableWindowScroll) {
|
|
491
489
|
const css = `
|
|
492
490
|
.taro_router {
|
|
493
491
|
position: relative;
|
|
@@ -498,13 +496,13 @@ function loadRouterStyle(usingWindowScroll) {
|
|
|
498
496
|
.taro_page {
|
|
499
497
|
width: 100%;
|
|
500
498
|
height: 100%;
|
|
501
|
-
|
|
499
|
+
${enableWindowScroll ? '' : `
|
|
502
500
|
overflow-x: hidden;
|
|
503
501
|
overflow-y: scroll;
|
|
504
502
|
max-height: 100vh;
|
|
505
|
-
|
|
503
|
+
`}
|
|
506
504
|
}
|
|
507
|
-
|
|
505
|
+
${enableTabBar ? `
|
|
508
506
|
.taro-tabbar__container > .taro-tabbar__panel {
|
|
509
507
|
overflow: hidden;
|
|
510
508
|
}
|
|
@@ -514,6 +512,7 @@ function loadRouterStyle(usingWindowScroll) {
|
|
|
514
512
|
max-height: calc(100vh - var(--taro-tabbar-height) - env(safe-area-inset-bottom));
|
|
515
513
|
}
|
|
516
514
|
|
|
515
|
+
` : ''}
|
|
517
516
|
.taro_page_shade,
|
|
518
517
|
.taro_router > .taro_page.taro_page_show.taro_page_stationed:not(.taro_page_shade):not(.taro_tabbar_page):not(:last-child) {
|
|
519
518
|
display: none;
|
|
@@ -529,38 +528,10 @@ function addStyle(css) {
|
|
|
529
528
|
document.getElementsByTagName('head')[0].appendChild(style);
|
|
530
529
|
}
|
|
531
530
|
|
|
532
|
-
// @ts-nocheck
|
|
533
|
-
function initTabbar(config) {
|
|
534
|
-
if (config.tabBar == null) {
|
|
535
|
-
return;
|
|
536
|
-
}
|
|
537
|
-
// TODO: custom-tab-bar
|
|
538
|
-
defineCustomElementTaroTabbar();
|
|
539
|
-
const tabbar = document.createElement('taro-tabbar');
|
|
540
|
-
const homePage = config.entryPagePath || (config.pages ? config.pages[0] : '');
|
|
541
|
-
tabbar.conf = config.tabBar;
|
|
542
|
-
tabbar.conf.homePage = history.location.pathname === '/' ? homePage : history.location.pathname;
|
|
543
|
-
const routerConfig = config.router;
|
|
544
|
-
tabbar.conf.mode = routerConfig && routerConfig.mode ? routerConfig.mode : 'hash';
|
|
545
|
-
if (routerConfig.customRoutes) {
|
|
546
|
-
tabbar.conf.custom = true;
|
|
547
|
-
tabbar.conf.customRoutes = routerConfig.customRoutes;
|
|
548
|
-
}
|
|
549
|
-
else {
|
|
550
|
-
tabbar.conf.custom = false;
|
|
551
|
-
tabbar.conf.customRoutes = {};
|
|
552
|
-
}
|
|
553
|
-
if (typeof routerConfig.basename !== 'undefined') {
|
|
554
|
-
tabbar.conf.basename = routerConfig.basename;
|
|
555
|
-
}
|
|
556
|
-
const container = document.getElementById('container');
|
|
557
|
-
container === null || container === void 0 ? void 0 : container.appendChild(tabbar);
|
|
558
|
-
initTabBarApis(config);
|
|
559
|
-
}
|
|
560
|
-
|
|
561
531
|
/* eslint-disable dot-notation */
|
|
562
532
|
class MultiPageHandler {
|
|
563
|
-
constructor(config) {
|
|
533
|
+
constructor(config, history) {
|
|
534
|
+
this.history = history;
|
|
564
535
|
this.config = config;
|
|
565
536
|
this.mount();
|
|
566
537
|
}
|
|
@@ -616,38 +587,9 @@ class MultiPageHandler {
|
|
|
616
587
|
return style !== 'custom';
|
|
617
588
|
}
|
|
618
589
|
mount() {
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
let app = document.getElementById(appId);
|
|
623
|
-
let isPosition = true;
|
|
624
|
-
if (!app) {
|
|
625
|
-
app = document.createElement('div');
|
|
626
|
-
app.id = appId;
|
|
627
|
-
isPosition = false;
|
|
628
|
-
}
|
|
629
|
-
const appWrapper = (app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body;
|
|
630
|
-
app.classList.add('taro_router');
|
|
631
|
-
if (this.tabBarList.length > 1) {
|
|
632
|
-
const container = document.createElement('div');
|
|
633
|
-
container.classList.add('taro-tabbar__container');
|
|
634
|
-
container.id = 'container';
|
|
635
|
-
const panel = document.createElement('div');
|
|
636
|
-
panel.classList.add('taro-tabbar__panel');
|
|
637
|
-
panel.appendChild(app.cloneNode(true));
|
|
638
|
-
container.appendChild(panel);
|
|
639
|
-
if (!isPosition) {
|
|
640
|
-
appWrapper.appendChild(container);
|
|
641
|
-
}
|
|
642
|
-
else {
|
|
643
|
-
appWrapper.replaceChild(container, app);
|
|
644
|
-
}
|
|
645
|
-
initTabbar(this.config);
|
|
646
|
-
}
|
|
647
|
-
else {
|
|
648
|
-
if (!isPosition)
|
|
649
|
-
appWrapper.appendChild(app);
|
|
650
|
-
}
|
|
590
|
+
setHistory(this.history, this.basename);
|
|
591
|
+
// Note: 注入页面样式
|
|
592
|
+
loadRouterStyle(this.tabBarList.length > 1, this.usingWindowScroll);
|
|
651
593
|
}
|
|
652
594
|
onReady(page, onLoad = true) {
|
|
653
595
|
var _a;
|
|
@@ -726,14 +668,14 @@ const launchStampId$1 = createStampId$1();
|
|
|
726
668
|
* - TabBar 会多次加载
|
|
727
669
|
* - 不支持路由动画
|
|
728
670
|
*/
|
|
729
|
-
function createMultiRouter(app, config, framework) {
|
|
671
|
+
function createMultiRouter(history, app, config, framework) {
|
|
730
672
|
var _a, _b, _c, _d, _e, _f;
|
|
731
673
|
return __awaiter(this, void 0, void 0, function* () {
|
|
732
674
|
if (typeof app.onUnhandledRejection === 'function') {
|
|
733
675
|
window.addEventListener('unhandledrejection', app.onUnhandledRejection);
|
|
734
676
|
}
|
|
735
677
|
RouterConfig.config = config;
|
|
736
|
-
const handler = new MultiPageHandler(config);
|
|
678
|
+
const handler = new MultiPageHandler(config, history);
|
|
737
679
|
const launchParam = {
|
|
738
680
|
path: config.pageName,
|
|
739
681
|
query: handler.getQuery(launchStampId$1),
|
|
@@ -782,7 +724,8 @@ function createMultiRouter(app, config, framework) {
|
|
|
782
724
|
|
|
783
725
|
/* eslint-disable dot-notation */
|
|
784
726
|
class PageHandler {
|
|
785
|
-
constructor(config) {
|
|
727
|
+
constructor(config, history) {
|
|
728
|
+
this.history = history;
|
|
786
729
|
this.defaultAnimation = { duration: 300, delay: 50 };
|
|
787
730
|
this.config = config;
|
|
788
731
|
this.homePage = getHomePage(this.routes[0].path, this.basename, this.customRoutes, this.config.entryPagePath);
|
|
@@ -888,40 +831,11 @@ class PageHandler {
|
|
|
888
831
|
return Object.assign(Object.assign({}, query), options);
|
|
889
832
|
}
|
|
890
833
|
mount() {
|
|
891
|
-
|
|
834
|
+
setHistory(this.history, this.basename);
|
|
892
835
|
this.pathname = history.location.pathname;
|
|
836
|
+
// Note: 注入页面样式
|
|
893
837
|
this.animation && loadAnimateStyle(this.animationDuration);
|
|
894
|
-
loadRouterStyle(this.usingWindowScroll);
|
|
895
|
-
const appId = this.appId;
|
|
896
|
-
let app = document.getElementById(appId);
|
|
897
|
-
let isPosition = true;
|
|
898
|
-
if (!app) {
|
|
899
|
-
app = document.createElement('div');
|
|
900
|
-
app.id = appId;
|
|
901
|
-
isPosition = false;
|
|
902
|
-
}
|
|
903
|
-
const appWrapper = (app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body;
|
|
904
|
-
app.classList.add('taro_router');
|
|
905
|
-
if (this.tabBarList.length > 1) {
|
|
906
|
-
const container = document.createElement('div');
|
|
907
|
-
container.classList.add('taro-tabbar__container');
|
|
908
|
-
container.id = 'container';
|
|
909
|
-
const panel = document.createElement('div');
|
|
910
|
-
panel.classList.add('taro-tabbar__panel');
|
|
911
|
-
panel.appendChild(app.cloneNode(true));
|
|
912
|
-
container.appendChild(panel);
|
|
913
|
-
if (!isPosition) {
|
|
914
|
-
appWrapper.appendChild(container);
|
|
915
|
-
}
|
|
916
|
-
else {
|
|
917
|
-
appWrapper.replaceChild(container, app);
|
|
918
|
-
}
|
|
919
|
-
initTabbar(this.config);
|
|
920
|
-
}
|
|
921
|
-
else {
|
|
922
|
-
if (!isPosition)
|
|
923
|
-
appWrapper.appendChild(app);
|
|
924
|
-
}
|
|
838
|
+
loadRouterStyle(this.tabBarList.length > 1, this.usingWindowScroll);
|
|
925
839
|
}
|
|
926
840
|
onReady(page, onLoad = true) {
|
|
927
841
|
var _a;
|
|
@@ -1121,13 +1035,13 @@ class PageHandler {
|
|
|
1121
1035
|
|
|
1122
1036
|
const createStampId = incrementId();
|
|
1123
1037
|
let launchStampId = createStampId();
|
|
1124
|
-
function createRouter(app, config, framework) {
|
|
1038
|
+
function createRouter(history, app, config, framework) {
|
|
1125
1039
|
var _a, _b;
|
|
1126
1040
|
if (typeof app.onUnhandledRejection === 'function') {
|
|
1127
1041
|
window.addEventListener('unhandledrejection', app.onUnhandledRejection);
|
|
1128
1042
|
}
|
|
1129
1043
|
RouterConfig.config = config;
|
|
1130
|
-
const handler = new PageHandler(config);
|
|
1044
|
+
const handler = new PageHandler(config, history);
|
|
1131
1045
|
routesAlias.set(handler.router.customRoutes);
|
|
1132
1046
|
const basename = handler.router.basename;
|
|
1133
1047
|
const routes = handler.routes.map(route => {
|
|
@@ -1301,5 +1215,43 @@ function createRouter(app, config, framework) {
|
|
|
1301
1215
|
return history.listen(render);
|
|
1302
1216
|
}
|
|
1303
1217
|
|
|
1304
|
-
|
|
1305
|
-
|
|
1218
|
+
function handleAppMount(config, _, appId = config.appId || 'app') {
|
|
1219
|
+
let app = document.getElementById(appId);
|
|
1220
|
+
let isPosition = true;
|
|
1221
|
+
if (!app) {
|
|
1222
|
+
app = document.createElement('div');
|
|
1223
|
+
app.id = appId;
|
|
1224
|
+
isPosition = false;
|
|
1225
|
+
}
|
|
1226
|
+
const appWrapper = (app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body;
|
|
1227
|
+
app.classList.add('taro_router');
|
|
1228
|
+
if (!isPosition)
|
|
1229
|
+
appWrapper.appendChild(app);
|
|
1230
|
+
}
|
|
1231
|
+
function handleAppMountWithTabbar(config, history, appId = config.appId || 'app') {
|
|
1232
|
+
let app = document.getElementById(appId);
|
|
1233
|
+
let isPosition = true;
|
|
1234
|
+
if (!app) {
|
|
1235
|
+
app = document.createElement('div');
|
|
1236
|
+
app.id = appId;
|
|
1237
|
+
isPosition = false;
|
|
1238
|
+
}
|
|
1239
|
+
const appWrapper = (app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body;
|
|
1240
|
+
app.classList.add('taro_router');
|
|
1241
|
+
const container = document.createElement('div');
|
|
1242
|
+
container.classList.add('taro-tabbar__container');
|
|
1243
|
+
container.id = 'container';
|
|
1244
|
+
const panel = document.createElement('div');
|
|
1245
|
+
panel.classList.add('taro-tabbar__panel');
|
|
1246
|
+
panel.appendChild(app.cloneNode(true));
|
|
1247
|
+
container.appendChild(panel);
|
|
1248
|
+
if (!isPosition) {
|
|
1249
|
+
appWrapper.appendChild(container);
|
|
1250
|
+
}
|
|
1251
|
+
else {
|
|
1252
|
+
appWrapper.replaceChild(container, app);
|
|
1253
|
+
}
|
|
1254
|
+
initTabbar(config, history);
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
export { createMpaHistory, createMultiRouter, createRouter, getCurrentPages, handleAppMount, handleAppMountWithTabbar, history, isDingTalk, isWeixin, navigateBack, navigateTo, prependBasename, reLaunch, redirectTo, routesAlias, setHistory, setHistoryMode, setTitle, switchTab };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
1
|
+
import { initTabbar } from './tabbar.js';
|
|
2
|
+
export { getCurrentPages, navigateBack, navigateTo, reLaunch, redirectTo, switchTab } from './api.js';
|
|
3
|
+
export { createMpaHistory, history, prependBasename, setHistory, setHistoryMode } from './history.js';
|
|
4
|
+
export { createMultiRouter } from './router/mpa.js';
|
|
5
|
+
export { createRouter } from './router/spa.js';
|
|
6
|
+
export { routesAlias } from './utils/index.js';
|
|
7
|
+
export { createBrowserHistory, createHashHistory } from 'history';
|
|
8
|
+
export { isDingTalk, isWeixin, setTitle } from './utils/navigate.js';
|
|
9
|
+
|
|
10
|
+
function handleAppMount(config, _, appId = config.appId || 'app') {
|
|
11
|
+
let app = document.getElementById(appId);
|
|
12
|
+
let isPosition = true;
|
|
13
|
+
if (!app) {
|
|
14
|
+
app = document.createElement('div');
|
|
15
|
+
app.id = appId;
|
|
16
|
+
isPosition = false;
|
|
17
|
+
}
|
|
18
|
+
const appWrapper = (app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body;
|
|
19
|
+
app.classList.add('taro_router');
|
|
20
|
+
if (!isPosition)
|
|
21
|
+
appWrapper.appendChild(app);
|
|
22
|
+
}
|
|
23
|
+
function handleAppMountWithTabbar(config, history, appId = config.appId || 'app') {
|
|
24
|
+
let app = document.getElementById(appId);
|
|
25
|
+
let isPosition = true;
|
|
26
|
+
if (!app) {
|
|
27
|
+
app = document.createElement('div');
|
|
28
|
+
app.id = appId;
|
|
29
|
+
isPosition = false;
|
|
30
|
+
}
|
|
31
|
+
const appWrapper = (app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body;
|
|
32
|
+
app.classList.add('taro_router');
|
|
33
|
+
const container = document.createElement('div');
|
|
34
|
+
container.classList.add('taro-tabbar__container');
|
|
35
|
+
container.id = 'container';
|
|
36
|
+
const panel = document.createElement('div');
|
|
37
|
+
panel.classList.add('taro-tabbar__panel');
|
|
38
|
+
panel.appendChild(app.cloneNode(true));
|
|
39
|
+
container.appendChild(panel);
|
|
40
|
+
if (!isPosition) {
|
|
41
|
+
appWrapper.appendChild(container);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
appWrapper.replaceChild(container, app);
|
|
45
|
+
}
|
|
46
|
+
initTabbar(config, history);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export { handleAppMount, handleAppMountWithTabbar };
|
package/dist/router/index.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { MpaRouterConfig, SpaRouterConfig } from '../../types/router';
|
|
2
|
+
declare class RouterConfig {
|
|
3
3
|
private static __config;
|
|
4
4
|
static set config(e: SpaRouterConfig | MpaRouterConfig);
|
|
5
5
|
static get config(): SpaRouterConfig | MpaRouterConfig;
|
|
6
6
|
static get pages(): string[];
|
|
7
|
-
static get router(): import("
|
|
7
|
+
static get router(): import("../types/router").Router;
|
|
8
8
|
static get mode(): "hash" | "browser" | "multi";
|
|
9
9
|
static get customRoutes(): Record<string, string | string[]>;
|
|
10
10
|
static isPage(url?: string): boolean;
|
|
11
11
|
}
|
|
12
|
+
export { RouterConfig };
|
package/dist/router/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { addLeadingSlash } from '
|
|
2
|
-
|
|
1
|
+
import { addLeadingSlash } from '@tarojs/runtime';
|
|
2
|
+
|
|
3
|
+
class RouterConfig {
|
|
3
4
|
static set config(e) {
|
|
4
5
|
this.__config = e;
|
|
5
6
|
}
|
|
@@ -20,3 +21,5 @@ export class RouterConfig {
|
|
|
20
21
|
return this.pages.findIndex(e => addLeadingSlash(e) === url) !== -1;
|
|
21
22
|
}
|
|
22
23
|
}
|
|
24
|
+
|
|
25
|
+
export { RouterConfig };
|
package/dist/router/mpa.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { AppInstance } from '@tarojs/runtime';
|
|
2
|
+
import { History } from "../history.js";
|
|
3
|
+
import { MpaRouterConfig } from '../../types/router';
|
|
3
4
|
/** Note: 关于多页面应用
|
|
4
5
|
* - 需要配置路由映射(根目录跳转、404 页面……)
|
|
5
6
|
* - app.onPageNotFound 事件不支持
|
|
@@ -7,4 +8,5 @@ import type { MpaRouterConfig } from '../../types/router';
|
|
|
7
8
|
* - TabBar 会多次加载
|
|
8
9
|
* - 不支持路由动画
|
|
9
10
|
*/
|
|
10
|
-
|
|
11
|
+
declare function createMultiRouter(history: History, app: AppInstance, config: MpaRouterConfig, framework?: string): Promise<void>;
|
|
12
|
+
export { createMultiRouter };
|