@tarojs/router 3.5.7 → 3.5.9
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 +1 -0
- package/dist/index.cjs.js +115 -50
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +116 -51
- package/dist/index.esm.js.map +1 -1
- package/dist/router/mpa.js +4 -2
- package/dist/router/multi-page.js +7 -5
- package/dist/router/page.d.ts +4 -4
- package/dist/router/page.js +21 -19
- package/dist/router/spa.js +62 -26
- package/dist/router/stack.d.ts +8 -0
- package/dist/router/stack.js +22 -0
- package/package.json +4 -4
package/dist/router/spa.js
CHANGED
|
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
/* eslint-disable dot-notation */
|
|
11
|
-
import { createPageConfig, Current, eventCenter, hooks, stringify } from '@tarojs/runtime';
|
|
11
|
+
import { createPageConfig, Current, eventCenter, hooks, incrementId, stringify, } from '@tarojs/runtime';
|
|
12
12
|
import { Action as LocationAction } from 'history';
|
|
13
13
|
import UniversalRouter from 'universal-router';
|
|
14
14
|
import { history, prependBasename } from '../history';
|
|
@@ -17,6 +17,8 @@ import { setTitle } from '../utils/navigate';
|
|
|
17
17
|
import { RouterConfig } from '.';
|
|
18
18
|
import PageHandler from './page';
|
|
19
19
|
import stacks from './stack';
|
|
20
|
+
const createStampId = incrementId();
|
|
21
|
+
let launchStampId = createStampId();
|
|
20
22
|
export function createRouter(app, config, framework) {
|
|
21
23
|
var _a, _b;
|
|
22
24
|
RouterConfig.config = config;
|
|
@@ -34,7 +36,7 @@ export function createRouter(app, config, framework) {
|
|
|
34
36
|
const router = new UniversalRouter(routes, { baseUrl: basename || '' });
|
|
35
37
|
const launchParam = {
|
|
36
38
|
path: handler.homePage,
|
|
37
|
-
query: handler.getQuery(
|
|
39
|
+
query: handler.getQuery(launchStampId),
|
|
38
40
|
scene: 0,
|
|
39
41
|
shareTicket: '',
|
|
40
42
|
referrerInfo: {}
|
|
@@ -43,7 +45,7 @@ export function createRouter(app, config, framework) {
|
|
|
43
45
|
(_a = app.onLaunch) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
|
|
44
46
|
app.onError && window.addEventListener('error', e => { var _a; return (_a = app.onError) === null || _a === void 0 ? void 0 : _a.call(app, e.message); });
|
|
45
47
|
const render = ({ location, action }) => __awaiter(this, void 0, void 0, function* () {
|
|
46
|
-
var _c, _d, _e, _f, _g;
|
|
48
|
+
var _c, _d, _e, _f, _g, _h;
|
|
47
49
|
handler.pathname = decodeURI(location.pathname);
|
|
48
50
|
eventCenter.trigger('__taroRouterChange', {
|
|
49
51
|
toLocation: {
|
|
@@ -82,8 +84,45 @@ export function createRouter(app, config, framework) {
|
|
|
82
84
|
}
|
|
83
85
|
const currentPage = Current.page;
|
|
84
86
|
const pathname = handler.pathname;
|
|
87
|
+
const methodName = (_g = stacks.method) !== null && _g !== void 0 ? _g : '';
|
|
88
|
+
const cacheTabs = stacks.getTabs();
|
|
85
89
|
let shouldLoad = false;
|
|
86
|
-
|
|
90
|
+
stacks.method = '';
|
|
91
|
+
if (methodName === 'reLaunch') {
|
|
92
|
+
handler.unload(currentPage, stacks.length);
|
|
93
|
+
// NOTE: 同时卸载缓存在tabs里面的页面实例
|
|
94
|
+
for (const key in cacheTabs) {
|
|
95
|
+
if (cacheTabs[key]) {
|
|
96
|
+
handler.unload(cacheTabs[key]);
|
|
97
|
+
stacks.removeTab(key);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
shouldLoad = true;
|
|
101
|
+
}
|
|
102
|
+
else if (handler.isTabBar(handler.pathname)) {
|
|
103
|
+
if (handler.isSamePage(currentPage))
|
|
104
|
+
return;
|
|
105
|
+
if (handler.isTabBar(currentPage.path)) {
|
|
106
|
+
handler.hide(currentPage);
|
|
107
|
+
stacks.pushTab(currentPage.path.split('?')[0]);
|
|
108
|
+
}
|
|
109
|
+
else if (stacks.length > 0) {
|
|
110
|
+
const firstIns = stacks.getItem(0);
|
|
111
|
+
if (handler.isTabBar(firstIns.path)) {
|
|
112
|
+
handler.unload(currentPage, stacks.length - 1);
|
|
113
|
+
stacks.pushTab(firstIns.path.split('?')[0]);
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
handler.unload(currentPage, stacks.length);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (cacheTabs[handler.pathname]) {
|
|
120
|
+
stacks.popTab(handler.pathname);
|
|
121
|
+
return handler.show(stacks.getItem(0), pageConfig, 0);
|
|
122
|
+
}
|
|
123
|
+
shouldLoad = true;
|
|
124
|
+
}
|
|
125
|
+
else if (action === 'POP') {
|
|
87
126
|
// NOTE: 浏览器事件退后多次时,该事件只会被触发一次
|
|
88
127
|
const prevIndex = stacks.getPrevIndex(pathname);
|
|
89
128
|
const delta = stacks.getDelta(pathname);
|
|
@@ -98,37 +137,34 @@ export function createRouter(app, config, framework) {
|
|
|
98
137
|
}
|
|
99
138
|
}
|
|
100
139
|
}
|
|
101
|
-
else {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
return handler.show(stacks.getItem(prevIndex), pageConfig, prevIndex);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
else if (action === 'REPLACE') {
|
|
113
|
-
const delta = stacks.getDelta(pathname);
|
|
114
|
-
// NOTE: 页面路由记录并不会清空,只是移除掉缓存的 stack 以及页面
|
|
115
|
-
handler.unload(currentPage, delta);
|
|
116
|
-
}
|
|
117
|
-
else if (action === 'PUSH') {
|
|
118
|
-
handler.hide(currentPage);
|
|
119
|
-
}
|
|
140
|
+
else if (action === 'REPLACE') {
|
|
141
|
+
const delta = stacks.getDelta(pathname);
|
|
142
|
+
// NOTE: 页面路由记录并不会清空,只是移除掉缓存的 stack 以及页面
|
|
143
|
+
handler.unload(currentPage, delta);
|
|
144
|
+
shouldLoad = true;
|
|
145
|
+
}
|
|
146
|
+
else if (action === 'PUSH') {
|
|
147
|
+
handler.hide(currentPage);
|
|
120
148
|
shouldLoad = true;
|
|
121
149
|
}
|
|
122
150
|
if (shouldLoad || stacks.length < 1) {
|
|
123
|
-
const el = (
|
|
151
|
+
const el = (_h = element.default) !== null && _h !== void 0 ? _h : element;
|
|
124
152
|
const loadConfig = Object.assign({}, pageConfig);
|
|
125
153
|
const stacksIndex = stacks.length;
|
|
126
154
|
delete loadConfig['path'];
|
|
127
155
|
delete loadConfig['load'];
|
|
128
|
-
|
|
156
|
+
let pageStampId = '';
|
|
157
|
+
if (launchStampId) {
|
|
158
|
+
pageStampId = launchStampId;
|
|
159
|
+
launchStampId = '';
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
pageStampId = createStampId();
|
|
163
|
+
}
|
|
164
|
+
const page = createPageConfig(enablePullDownRefresh ? hooks.call('createPullDownComponent', el, location.pathname, framework, handler.PullDownRefresh) : el, pathname + stringify(handler.getQuery(pageStampId)), {}, loadConfig);
|
|
129
165
|
if (params)
|
|
130
166
|
page.options = params;
|
|
131
|
-
return handler.load(page, pageConfig, stacksIndex);
|
|
167
|
+
return handler.load(page, pageConfig, pageStampId, stacksIndex);
|
|
132
168
|
}
|
|
133
169
|
});
|
|
134
170
|
const routePath = addLeadingSlash(stripBasename(history.location.pathname, handler.basename));
|
package/dist/router/stack.d.ts
CHANGED
|
@@ -2,8 +2,12 @@ import { PageInstance } from '@tarojs/runtime';
|
|
|
2
2
|
declare class Stacks {
|
|
3
3
|
stacks: PageInstance[];
|
|
4
4
|
backDelta: number;
|
|
5
|
+
tabs: {};
|
|
6
|
+
methodName: string;
|
|
5
7
|
set delta(delta: number);
|
|
6
8
|
get delta(): number;
|
|
9
|
+
set method(methodName: string);
|
|
10
|
+
get method(): string;
|
|
7
11
|
get length(): number;
|
|
8
12
|
get last(): PageInstance;
|
|
9
13
|
get(): PageInstance[];
|
|
@@ -13,6 +17,10 @@ declare class Stacks {
|
|
|
13
17
|
getPrevIndex(pathname: string, stateWith?: number): number;
|
|
14
18
|
pop(): PageInstance | undefined;
|
|
15
19
|
push(page: PageInstance): number;
|
|
20
|
+
getTabs(): {};
|
|
21
|
+
pushTab(path: string): void;
|
|
22
|
+
popTab(path: string): void;
|
|
23
|
+
removeTab(path: string): void;
|
|
16
24
|
}
|
|
17
25
|
declare const stacks: Stacks;
|
|
18
26
|
export default stacks;
|
package/dist/router/stack.js
CHANGED
|
@@ -2,6 +2,8 @@ class Stacks {
|
|
|
2
2
|
constructor() {
|
|
3
3
|
this.stacks = [];
|
|
4
4
|
this.backDelta = 0;
|
|
5
|
+
this.tabs = {};
|
|
6
|
+
this.methodName = '';
|
|
5
7
|
}
|
|
6
8
|
set delta(delta) {
|
|
7
9
|
if (delta > 0) {
|
|
@@ -17,6 +19,12 @@ class Stacks {
|
|
|
17
19
|
get delta() {
|
|
18
20
|
return this.backDelta;
|
|
19
21
|
}
|
|
22
|
+
set method(methodName) {
|
|
23
|
+
this.methodName = methodName;
|
|
24
|
+
}
|
|
25
|
+
get method() {
|
|
26
|
+
return this.methodName;
|
|
27
|
+
}
|
|
20
28
|
get length() {
|
|
21
29
|
return this.stacks.length;
|
|
22
30
|
}
|
|
@@ -54,6 +62,20 @@ class Stacks {
|
|
|
54
62
|
push(page) {
|
|
55
63
|
return this.stacks.push(page);
|
|
56
64
|
}
|
|
65
|
+
getTabs() {
|
|
66
|
+
return this.tabs;
|
|
67
|
+
}
|
|
68
|
+
pushTab(path) {
|
|
69
|
+
this.tabs[path] = this.last;
|
|
70
|
+
this.pop();
|
|
71
|
+
}
|
|
72
|
+
popTab(path) {
|
|
73
|
+
this.push(this.tabs[path]);
|
|
74
|
+
delete this.tabs[path];
|
|
75
|
+
}
|
|
76
|
+
removeTab(path) {
|
|
77
|
+
delete this.tabs[path];
|
|
78
|
+
}
|
|
57
79
|
}
|
|
58
80
|
const stacks = new Stacks();
|
|
59
81
|
export default stacks;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tarojs/router",
|
|
3
|
-
"version": "3.5.
|
|
3
|
+
"version": "3.5.9",
|
|
4
4
|
"description": "Taro-router",
|
|
5
5
|
"browser": "dist/index.esm.js",
|
|
6
6
|
"main:h5": "dist/index.js",
|
|
@@ -22,13 +22,13 @@
|
|
|
22
22
|
"author": "O2Team",
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@tarojs/runtime": "3.5.7",
|
|
26
|
-
"@tarojs/taro": "3.5.7",
|
|
27
25
|
"dingtalk-jsapi": "~2.15.2",
|
|
28
26
|
"history": "^5.1.0",
|
|
29
27
|
"mobile-detect": "^1.4.2",
|
|
30
28
|
"query-string": "^7.1.1",
|
|
31
|
-
"universal-router": "^8.3.0"
|
|
29
|
+
"universal-router": "^8.3.0",
|
|
30
|
+
"@tarojs/runtime": "3.5.9",
|
|
31
|
+
"@tarojs/taro": "3.5.9"
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|
|
34
34
|
"build": "rimraf ./dist && tsc && rollup -c",
|