@tarojs/router 3.5.0-theta.1 → 3.5.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/dist/events/scroll.js +2 -1
- package/dist/index.cjs.js +58 -15
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +57 -15
- package/dist/index.esm.js.map +1 -1
- package/dist/router/mpa.js +3 -1
- package/dist/router/multi-page.d.ts +1 -1
- package/dist/router/multi-page.js +1 -1
- package/dist/router/page.d.ts +1 -1
- package/dist/router/page.js +4 -4
- package/dist/router/spa.js +14 -8
- package/dist/{utils.d.ts → utils/index.d.ts} +2 -0
- package/dist/{utils.js → utils/index.js} +5 -1
- package/dist/utils/navigate.d.ts +5 -0
- package/dist/utils/navigate.js +44 -0
- package/package.json +5 -3
- package/types/router.d.ts +2 -2
package/dist/router/spa.js
CHANGED
|
@@ -13,6 +13,7 @@ import { Action as LocationAction } from 'history';
|
|
|
13
13
|
import UniversalRouter from 'universal-router';
|
|
14
14
|
import { history, prependBasename } from '../history';
|
|
15
15
|
import { addLeadingSlash, routesAlias, stripBasename } from '../utils';
|
|
16
|
+
import { setTitle } from '../utils/navigate';
|
|
16
17
|
import { RouterConfig } from '.';
|
|
17
18
|
import PageHandler from './page';
|
|
18
19
|
import stacks from './stack';
|
|
@@ -33,8 +34,9 @@ export function createRouter(app, config, framework) {
|
|
|
33
34
|
const router = new UniversalRouter(routes, { baseUrl: basename || '' });
|
|
34
35
|
const launchParam = handler.getQuery(stacks.length);
|
|
35
36
|
(_a = app.onLaunch) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
|
|
37
|
+
app.onError && window.addEventListener('error', e => { var _a; return (_a = app.onError) === null || _a === void 0 ? void 0 : _a.call(app, e.message); });
|
|
36
38
|
const render = ({ location, action }) => __awaiter(this, void 0, void 0, function* () {
|
|
37
|
-
var _c, _d, _e, _f;
|
|
39
|
+
var _c, _d, _e, _f, _g;
|
|
38
40
|
handler.pathname = decodeURI(location.pathname);
|
|
39
41
|
let element, params;
|
|
40
42
|
try {
|
|
@@ -62,6 +64,7 @@ export function createRouter(app, config, framework) {
|
|
|
62
64
|
});
|
|
63
65
|
if (pageConfig) {
|
|
64
66
|
document.title = (_e = pageConfig.navigationBarTitleText) !== null && _e !== void 0 ? _e : document.title;
|
|
67
|
+
setTitle((_f = pageConfig.navigationBarTitleText) !== null && _f !== void 0 ? _f : document.title);
|
|
65
68
|
if (typeof pageConfig.enablePullDownRefresh === 'boolean') {
|
|
66
69
|
enablePullDownRefresh = pageConfig.enablePullDownRefresh;
|
|
67
70
|
}
|
|
@@ -73,12 +76,15 @@ export function createRouter(app, config, framework) {
|
|
|
73
76
|
// NOTE: 浏览器事件退后多次时,该事件只会被触发一次
|
|
74
77
|
const prevIndex = stacks.getPrevIndex(pathname);
|
|
75
78
|
const delta = stacks.getDelta(pathname);
|
|
76
|
-
|
|
77
|
-
if (
|
|
78
|
-
handler.
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
// NOTE: Safari 内核浏览器在非应用页面返回上一页时,会触发额外的 POP 事件,此处需避免当前页面被错误卸载
|
|
80
|
+
if (currentPage !== stacks.getItem(prevIndex)) {
|
|
81
|
+
handler.unload(currentPage, delta, prevIndex > -1);
|
|
82
|
+
if (prevIndex > -1) {
|
|
83
|
+
handler.show(stacks.getItem(prevIndex), pageConfig, prevIndex);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
shouldLoad = true;
|
|
87
|
+
}
|
|
82
88
|
}
|
|
83
89
|
}
|
|
84
90
|
else {
|
|
@@ -103,7 +109,7 @@ export function createRouter(app, config, framework) {
|
|
|
103
109
|
shouldLoad = true;
|
|
104
110
|
}
|
|
105
111
|
if (shouldLoad || stacks.length < 1) {
|
|
106
|
-
const el = (
|
|
112
|
+
const el = (_g = element.default) !== null && _g !== void 0 ? _g : element;
|
|
107
113
|
const loadConfig = Object.assign({}, pageConfig);
|
|
108
114
|
const stacksIndex = stacks.length;
|
|
109
115
|
delete loadConfig['path'];
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export declare const addLeadingSlash: (url?: string) => string;
|
|
2
2
|
export declare const hasBasename: (path?: string, prefix?: string) => boolean;
|
|
3
3
|
export declare const stripBasename: (path?: string, prefix?: string) => string;
|
|
4
|
+
export declare const stripTrailing: (str?: string) => string;
|
|
5
|
+
export declare const stripSuffix: (path?: string, suffix?: string) => string;
|
|
4
6
|
declare class RoutesAlias {
|
|
5
7
|
conf: Array<string[]>;
|
|
6
8
|
set(customRoutes?: Record<string, string | string[]>): void;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
// export const removeLeadingSlash = (str = '') => str.replace(/^\.?\//, '')
|
|
2
|
+
// export const removeTrailingSearch = (str = '') => str.replace(/\?[\s\S]*$/, '')
|
|
1
3
|
export const addLeadingSlash = (url = '') => (url.charAt(0) === '/' ? url : '/' + url);
|
|
2
4
|
export const hasBasename = (path = '', prefix = '') => new RegExp('^' + prefix + '(\\/|\\?|#|$)', 'i').test(path) || path === prefix;
|
|
3
|
-
export const stripBasename = (path = '', prefix = '') => hasBasename(path, prefix) ? path.
|
|
5
|
+
export const stripBasename = (path = '', prefix = '') => hasBasename(path, prefix) ? path.substring(prefix.length) : path;
|
|
6
|
+
export const stripTrailing = (str = '') => str.replace(/[?#][\s\S]*$/, '');
|
|
7
|
+
export const stripSuffix = (path = '', suffix = '') => path.includes(suffix) ? path.substring(0, path.length - suffix.length) : path;
|
|
4
8
|
class RoutesAlias {
|
|
5
9
|
constructor() {
|
|
6
10
|
this.conf = [];
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import MobileDetect from 'mobile-detect';
|
|
11
|
+
let md;
|
|
12
|
+
let preTitle = document.title;
|
|
13
|
+
let isLoadDdEntry = false;
|
|
14
|
+
export function getMobileDetect() {
|
|
15
|
+
if (!md) {
|
|
16
|
+
md = new MobileDetect(navigator.userAgent);
|
|
17
|
+
}
|
|
18
|
+
return md;
|
|
19
|
+
}
|
|
20
|
+
export function setTitle(title) {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
if (preTitle === title)
|
|
23
|
+
return title;
|
|
24
|
+
document.title = title;
|
|
25
|
+
preTitle = title;
|
|
26
|
+
if (process.env.SUPPORT_DINGTALK_NAVIGATE !== 'disabled' && isDingTalk()) {
|
|
27
|
+
if (!isLoadDdEntry) {
|
|
28
|
+
isLoadDdEntry = true;
|
|
29
|
+
require('dingtalk-jsapi/platform');
|
|
30
|
+
}
|
|
31
|
+
const setDingTitle = require('dingtalk-jsapi/api/biz/navigation/setTitle').default;
|
|
32
|
+
setDingTitle({ title });
|
|
33
|
+
}
|
|
34
|
+
return title;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
export function isWeixin() {
|
|
38
|
+
const md = getMobileDetect();
|
|
39
|
+
return md.match(/MicroMessenger/ig);
|
|
40
|
+
}
|
|
41
|
+
export function isDingTalk() {
|
|
42
|
+
const md = getMobileDetect();
|
|
43
|
+
return md.match(/DingTalk/ig);
|
|
44
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tarojs/router",
|
|
3
|
-
"version": "3.5.0
|
|
3
|
+
"version": "3.5.0",
|
|
4
4
|
"description": "Taro-router",
|
|
5
5
|
"browser": "dist/index.esm.js",
|
|
6
6
|
"main:h5": "dist/index.js",
|
|
@@ -22,9 +22,11 @@
|
|
|
22
22
|
"author": "O2Team",
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@tarojs/runtime": "3.5.0
|
|
26
|
-
"@tarojs/taro": "3.5.0
|
|
25
|
+
"@tarojs/runtime": "3.5.0",
|
|
26
|
+
"@tarojs/taro": "3.5.0",
|
|
27
|
+
"dingtalk-jsapi": "~2.15.2",
|
|
27
28
|
"history": "^5.1.0",
|
|
29
|
+
"mobile-detect": "^1.4.2",
|
|
28
30
|
"query-string": "^7.1.1",
|
|
29
31
|
"universal-router": "^8.3.0"
|
|
30
32
|
},
|
package/types/router.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AppConfig, PageConfig } from '@tarojs/taro'
|
|
2
|
-
import { IH5RouterConfig } from '@tarojs/taro/types/compile'
|
|
1
|
+
import type { AppConfig, PageConfig } from '@tarojs/taro'
|
|
2
|
+
import type { IH5RouterConfig } from '@tarojs/taro/types/compile'
|
|
3
3
|
|
|
4
4
|
export interface Route extends PageConfig {
|
|
5
5
|
path?: string
|