@tinkoff/router 0.3.21 → 0.3.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.
|
@@ -20,7 +20,7 @@ const generatePreviousNavigateState = (navigation) => {
|
|
|
20
20
|
}
|
|
21
21
|
return state;
|
|
22
22
|
};
|
|
23
|
-
const generateState = (navigation, currentState) => {
|
|
23
|
+
const generateState = (navigation, currentState, index = 0) => {
|
|
24
24
|
const key = generateKey(navigation);
|
|
25
25
|
const previousNavigateState = generatePreviousNavigateState(navigation);
|
|
26
26
|
let { type } = navigation;
|
|
@@ -35,6 +35,7 @@ const generateState = (navigation, currentState) => {
|
|
|
35
35
|
key,
|
|
36
36
|
type,
|
|
37
37
|
navigateState,
|
|
38
|
+
index,
|
|
38
39
|
};
|
|
39
40
|
};
|
|
40
41
|
class ClientHistory extends History {
|
|
@@ -56,6 +57,7 @@ class ClientHistory extends History {
|
|
|
56
57
|
this.currentState = isHistoryState((_a = window.history) === null || _a === void 0 ? void 0 : _a.state)
|
|
57
58
|
? window.history.state
|
|
58
59
|
: generateState(navigation);
|
|
60
|
+
this.currentIndex = this.currentState.index;
|
|
59
61
|
this.historyWrapper.init(this.currentState);
|
|
60
62
|
this.historyWrapper.subscribe(async ({ path, state }) => {
|
|
61
63
|
var _a, _b;
|
|
@@ -97,7 +99,7 @@ class ClientHistory extends History {
|
|
|
97
99
|
if (!replace) {
|
|
98
100
|
this.currentIndex++;
|
|
99
101
|
}
|
|
100
|
-
this.currentState = generateState(navigation, this.currentState);
|
|
102
|
+
this.currentState = generateState(navigation, this.currentState, this.currentIndex);
|
|
101
103
|
this.historyWrapper.navigate({
|
|
102
104
|
path: url.path,
|
|
103
105
|
replace,
|
|
@@ -106,13 +108,13 @@ class ClientHistory extends History {
|
|
|
106
108
|
}
|
|
107
109
|
go(to, options) {
|
|
108
110
|
var _a;
|
|
109
|
-
|
|
110
|
-
if (index < 0) {
|
|
111
|
+
if (this.currentIndex < 1) {
|
|
111
112
|
if (options === null || options === void 0 ? void 0 : options.historyFallback) {
|
|
112
113
|
return this.listener({
|
|
113
114
|
url: options.historyFallback,
|
|
114
115
|
type: 'navigate',
|
|
115
116
|
history: false,
|
|
117
|
+
replace: options.replace,
|
|
116
118
|
});
|
|
117
119
|
}
|
|
118
120
|
const historyFallbackRoute = (_a = this.tree) === null || _a === void 0 ? void 0 : _a.getHistoryFallback(window.location.pathname);
|
|
@@ -124,6 +126,7 @@ class ClientHistory extends History {
|
|
|
124
126
|
});
|
|
125
127
|
}
|
|
126
128
|
}
|
|
129
|
+
this.currentIndex += to;
|
|
127
130
|
const promise = new Promise((resolve, reject) => {
|
|
128
131
|
this.goPromiseResolve = resolve;
|
|
129
132
|
this.goPromiseReject = reject;
|
package/lib/history/client.d.ts
CHANGED
package/lib/history/client.es.js
CHANGED
|
@@ -20,7 +20,7 @@ const generatePreviousNavigateState = (navigation) => {
|
|
|
20
20
|
}
|
|
21
21
|
return state;
|
|
22
22
|
};
|
|
23
|
-
const generateState = (navigation, currentState) => {
|
|
23
|
+
const generateState = (navigation, currentState, index = 0) => {
|
|
24
24
|
const key = generateKey(navigation);
|
|
25
25
|
const previousNavigateState = generatePreviousNavigateState(navigation);
|
|
26
26
|
let { type } = navigation;
|
|
@@ -35,6 +35,7 @@ const generateState = (navigation, currentState) => {
|
|
|
35
35
|
key,
|
|
36
36
|
type,
|
|
37
37
|
navigateState,
|
|
38
|
+
index,
|
|
38
39
|
};
|
|
39
40
|
};
|
|
40
41
|
class ClientHistory extends History {
|
|
@@ -56,6 +57,7 @@ class ClientHistory extends History {
|
|
|
56
57
|
this.currentState = isHistoryState((_a = window.history) === null || _a === void 0 ? void 0 : _a.state)
|
|
57
58
|
? window.history.state
|
|
58
59
|
: generateState(navigation);
|
|
60
|
+
this.currentIndex = this.currentState.index;
|
|
59
61
|
this.historyWrapper.init(this.currentState);
|
|
60
62
|
this.historyWrapper.subscribe(async ({ path, state }) => {
|
|
61
63
|
var _a, _b;
|
|
@@ -97,7 +99,7 @@ class ClientHistory extends History {
|
|
|
97
99
|
if (!replace) {
|
|
98
100
|
this.currentIndex++;
|
|
99
101
|
}
|
|
100
|
-
this.currentState = generateState(navigation, this.currentState);
|
|
102
|
+
this.currentState = generateState(navigation, this.currentState, this.currentIndex);
|
|
101
103
|
this.historyWrapper.navigate({
|
|
102
104
|
path: url.path,
|
|
103
105
|
replace,
|
|
@@ -106,13 +108,13 @@ class ClientHistory extends History {
|
|
|
106
108
|
}
|
|
107
109
|
go(to, options) {
|
|
108
110
|
var _a;
|
|
109
|
-
|
|
110
|
-
if (index < 0) {
|
|
111
|
+
if (this.currentIndex < 1) {
|
|
111
112
|
if (options === null || options === void 0 ? void 0 : options.historyFallback) {
|
|
112
113
|
return this.listener({
|
|
113
114
|
url: options.historyFallback,
|
|
114
115
|
type: 'navigate',
|
|
115
116
|
history: false,
|
|
117
|
+
replace: options.replace,
|
|
116
118
|
});
|
|
117
119
|
}
|
|
118
120
|
const historyFallbackRoute = (_a = this.tree) === null || _a === void 0 ? void 0 : _a.getHistoryFallback(window.location.pathname);
|
|
@@ -124,6 +126,7 @@ class ClientHistory extends History {
|
|
|
124
126
|
});
|
|
125
127
|
}
|
|
126
128
|
}
|
|
129
|
+
this.currentIndex += to;
|
|
127
130
|
const promise = new Promise((resolve, reject) => {
|
|
128
131
|
this.goPromiseResolve = resolve;
|
|
129
132
|
this.goPromiseReject = reject;
|
package/lib/history/client.js
CHANGED
|
@@ -24,7 +24,7 @@ const generatePreviousNavigateState = (navigation) => {
|
|
|
24
24
|
}
|
|
25
25
|
return state;
|
|
26
26
|
};
|
|
27
|
-
const generateState = (navigation, currentState) => {
|
|
27
|
+
const generateState = (navigation, currentState, index = 0) => {
|
|
28
28
|
const key = generateKey(navigation);
|
|
29
29
|
const previousNavigateState = generatePreviousNavigateState(navigation);
|
|
30
30
|
let { type } = navigation;
|
|
@@ -39,6 +39,7 @@ const generateState = (navigation, currentState) => {
|
|
|
39
39
|
key,
|
|
40
40
|
type,
|
|
41
41
|
navigateState,
|
|
42
|
+
index,
|
|
42
43
|
};
|
|
43
44
|
};
|
|
44
45
|
class ClientHistory extends base.History {
|
|
@@ -60,6 +61,7 @@ class ClientHistory extends base.History {
|
|
|
60
61
|
this.currentState = isHistoryState((_a = window.history) === null || _a === void 0 ? void 0 : _a.state)
|
|
61
62
|
? window.history.state
|
|
62
63
|
: generateState(navigation);
|
|
64
|
+
this.currentIndex = this.currentState.index;
|
|
63
65
|
this.historyWrapper.init(this.currentState);
|
|
64
66
|
this.historyWrapper.subscribe(async ({ path, state }) => {
|
|
65
67
|
var _a, _b;
|
|
@@ -101,7 +103,7 @@ class ClientHistory extends base.History {
|
|
|
101
103
|
if (!replace) {
|
|
102
104
|
this.currentIndex++;
|
|
103
105
|
}
|
|
104
|
-
this.currentState = generateState(navigation, this.currentState);
|
|
106
|
+
this.currentState = generateState(navigation, this.currentState, this.currentIndex);
|
|
105
107
|
this.historyWrapper.navigate({
|
|
106
108
|
path: url.path,
|
|
107
109
|
replace,
|
|
@@ -110,13 +112,13 @@ class ClientHistory extends base.History {
|
|
|
110
112
|
}
|
|
111
113
|
go(to, options) {
|
|
112
114
|
var _a;
|
|
113
|
-
|
|
114
|
-
if (index < 0) {
|
|
115
|
+
if (this.currentIndex < 1) {
|
|
115
116
|
if (options === null || options === void 0 ? void 0 : options.historyFallback) {
|
|
116
117
|
return this.listener({
|
|
117
118
|
url: options.historyFallback,
|
|
118
119
|
type: 'navigate',
|
|
119
120
|
history: false,
|
|
121
|
+
replace: options.replace,
|
|
120
122
|
});
|
|
121
123
|
}
|
|
122
124
|
const historyFallbackRoute = (_a = this.tree) === null || _a === void 0 ? void 0 : _a.getHistoryFallback(window.location.pathname);
|
|
@@ -128,6 +130,7 @@ class ClientHistory extends base.History {
|
|
|
128
130
|
});
|
|
129
131
|
}
|
|
130
132
|
}
|
|
133
|
+
this.currentIndex += to;
|
|
131
134
|
const promise = new Promise((resolve, reject) => {
|
|
132
135
|
this.goPromiseResolve = resolve;
|
|
133
136
|
this.goPromiseReject = reject;
|
package/lib/types.d.ts
CHANGED
|
@@ -31,6 +31,7 @@ export interface NavigateOptions extends BaseNavigateOptions {
|
|
|
31
31
|
export type UpdateCurrentRouteOptions = BaseNavigateOptions;
|
|
32
32
|
export interface HistoryOptions {
|
|
33
33
|
historyFallback: string;
|
|
34
|
+
replace?: boolean;
|
|
34
35
|
}
|
|
35
36
|
export type NavigationType = 'navigate' | 'updateCurrentRoute';
|
|
36
37
|
export interface Navigation {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tinkoff/router",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.23",
|
|
4
4
|
"description": "router",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"use-sync-external-store": "^1.2.0"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"@tramvai/core": "3.
|
|
30
|
+
"@tramvai/core": "3.17.0",
|
|
31
31
|
"react": ">=16.14.0",
|
|
32
32
|
"tslib": "^2.4.0"
|
|
33
33
|
},
|