@tinkoff/router 0.6.122 → 0.6.152
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/lib/history/client.browser.js +34 -6
- package/lib/history/client.d.ts +5 -2
- package/lib/history/client.es.js +34 -6
- package/lib/history/client.js +34 -6
- package/lib/index.browser.js +1 -0
- package/lib/index.es.js +1 -0
- package/lib/index.js +5 -0
- package/lib/router/abstract.browser.js +5 -7
- package/lib/router/abstract.d.ts +3 -2
- package/lib/router/abstract.es.js +5 -7
- package/lib/router/abstract.js +5 -7
- package/lib/router/browser.browser.js +23 -15
- package/lib/router/browser.d.ts +2 -2
- package/lib/router/client.browser.js +6 -2
- package/lib/router/client.es.js +6 -2
- package/lib/router/client.js +6 -2
- package/lib/types.browser.js +14 -0
- package/lib/types.d.ts +12 -2
- package/lib/types.es.js +14 -0
- package/lib/types.js +16 -0
- package/package.json +5 -5
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { History } from './base.browser.js';
|
|
2
|
+
import { BackNavigationType } from '../types.browser.js';
|
|
2
3
|
import { wrapHistory } from './wrapper.browser.js';
|
|
3
4
|
|
|
4
5
|
const isHistoryState = (state) => {
|
|
@@ -55,8 +56,9 @@ class ClientHistory extends History {
|
|
|
55
56
|
currentIndex = 0;
|
|
56
57
|
currentState;
|
|
57
58
|
historyUnsubscribeCallback;
|
|
59
|
+
backNavigationWithinRouteType;
|
|
58
60
|
historyWrapper;
|
|
59
|
-
constructor() {
|
|
61
|
+
constructor({ backNavigationWithinRouteType, } = {}) {
|
|
60
62
|
super();
|
|
61
63
|
this.historyWrapper = wrapHistory({
|
|
62
64
|
onNavigate: ({ url, replace, navigateState }) => {
|
|
@@ -67,6 +69,8 @@ class ClientHistory extends History {
|
|
|
67
69
|
});
|
|
68
70
|
},
|
|
69
71
|
});
|
|
72
|
+
this.backNavigationWithinRouteType =
|
|
73
|
+
backNavigationWithinRouteType ?? BackNavigationType.PREFER_UPDATE;
|
|
70
74
|
}
|
|
71
75
|
onNavigate;
|
|
72
76
|
getCurrentState() {
|
|
@@ -78,7 +82,9 @@ class ClientHistory extends History {
|
|
|
78
82
|
: generateState(navigation);
|
|
79
83
|
this.currentIndex = this.currentState.index;
|
|
80
84
|
this.historyWrapper.init(this.currentState);
|
|
81
|
-
this.historyUnsubscribeCallback = this.historyWrapper.subscribe(
|
|
85
|
+
this.historyUnsubscribeCallback = this.historyWrapper.subscribe(
|
|
86
|
+
// eslint-disable-next-line max-statements
|
|
87
|
+
async ({ path, state, hasUAVisualTransition }) => {
|
|
82
88
|
try {
|
|
83
89
|
let navigationType;
|
|
84
90
|
let navigateState;
|
|
@@ -89,12 +95,34 @@ class ClientHistory extends History {
|
|
|
89
95
|
const { key, type } = state;
|
|
90
96
|
this.currentState = state;
|
|
91
97
|
navigateState = state.navigateState;
|
|
92
|
-
if (key
|
|
93
|
-
|
|
94
|
-
navigationType = 'updateCurrentRoute';
|
|
98
|
+
if (key !== prevKey) {
|
|
99
|
+
navigateState = 'navigate';
|
|
95
100
|
}
|
|
96
101
|
else {
|
|
97
|
-
|
|
102
|
+
if (this.backNavigationWithinRouteType === BackNavigationType.PREFER_UPDATE) {
|
|
103
|
+
if (type === 'updateCurrentRoute' || prevType === 'updateCurrentRoute') {
|
|
104
|
+
navigationType = 'updateCurrentRoute';
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
navigationType = 'navigate';
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (this.backNavigationWithinRouteType === BackNavigationType.CURRENT_TYPE) {
|
|
111
|
+
if (isBack ? prevType === 'updateCurrentRoute' : type === 'updateCurrentRoute') {
|
|
112
|
+
navigationType = 'updateCurrentRoute';
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
navigationType = 'navigate';
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (this.backNavigationWithinRouteType === BackNavigationType.PREVIOUS_TYPE) {
|
|
119
|
+
if (isBack ? type === 'updateCurrentRoute' : type === 'updateCurrentRoute') {
|
|
120
|
+
navigationType = 'updateCurrentRoute';
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
navigationType = 'navigate';
|
|
124
|
+
}
|
|
125
|
+
}
|
|
98
126
|
}
|
|
99
127
|
}
|
|
100
128
|
else {
|
package/lib/history/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { History } from './base';
|
|
2
|
-
import
|
|
2
|
+
import { HistoryOptions, HistoryState, Navigation, BackNavigationType } from '../types';
|
|
3
3
|
import type { Wrapper } from './wrapper';
|
|
4
4
|
import { wrapHistory } from './wrapper';
|
|
5
5
|
export declare class ClientHistory extends History {
|
|
@@ -8,8 +8,11 @@ export declare class ClientHistory extends History {
|
|
|
8
8
|
private currentIndex;
|
|
9
9
|
private currentState;
|
|
10
10
|
private historyUnsubscribeCallback;
|
|
11
|
+
private backNavigationWithinRouteType;
|
|
11
12
|
protected historyWrapper: Wrapper<HistoryState>;
|
|
12
|
-
constructor(
|
|
13
|
+
constructor({ backNavigationWithinRouteType, }?: {
|
|
14
|
+
backNavigationWithinRouteType?: BackNavigationType;
|
|
15
|
+
});
|
|
13
16
|
protected onNavigate: Parameters<typeof wrapHistory>[0]['onNavigate'];
|
|
14
17
|
getCurrentState(): HistoryState | undefined;
|
|
15
18
|
init(navigation: Navigation): void;
|
package/lib/history/client.es.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { History } from './base.es.js';
|
|
2
|
+
import { BackNavigationType } from '../types.es.js';
|
|
2
3
|
import { wrapHistory } from './wrapper.es.js';
|
|
3
4
|
|
|
4
5
|
const isHistoryState = (state) => {
|
|
@@ -55,8 +56,9 @@ class ClientHistory extends History {
|
|
|
55
56
|
currentIndex = 0;
|
|
56
57
|
currentState;
|
|
57
58
|
historyUnsubscribeCallback;
|
|
59
|
+
backNavigationWithinRouteType;
|
|
58
60
|
historyWrapper;
|
|
59
|
-
constructor() {
|
|
61
|
+
constructor({ backNavigationWithinRouteType, } = {}) {
|
|
60
62
|
super();
|
|
61
63
|
this.historyWrapper = wrapHistory({
|
|
62
64
|
onNavigate: ({ url, replace, navigateState }) => {
|
|
@@ -67,6 +69,8 @@ class ClientHistory extends History {
|
|
|
67
69
|
});
|
|
68
70
|
},
|
|
69
71
|
});
|
|
72
|
+
this.backNavigationWithinRouteType =
|
|
73
|
+
backNavigationWithinRouteType ?? BackNavigationType.PREFER_UPDATE;
|
|
70
74
|
}
|
|
71
75
|
onNavigate;
|
|
72
76
|
getCurrentState() {
|
|
@@ -78,7 +82,9 @@ class ClientHistory extends History {
|
|
|
78
82
|
: generateState(navigation);
|
|
79
83
|
this.currentIndex = this.currentState.index;
|
|
80
84
|
this.historyWrapper.init(this.currentState);
|
|
81
|
-
this.historyUnsubscribeCallback = this.historyWrapper.subscribe(
|
|
85
|
+
this.historyUnsubscribeCallback = this.historyWrapper.subscribe(
|
|
86
|
+
// eslint-disable-next-line max-statements
|
|
87
|
+
async ({ path, state, hasUAVisualTransition }) => {
|
|
82
88
|
try {
|
|
83
89
|
let navigationType;
|
|
84
90
|
let navigateState;
|
|
@@ -89,12 +95,34 @@ class ClientHistory extends History {
|
|
|
89
95
|
const { key, type } = state;
|
|
90
96
|
this.currentState = state;
|
|
91
97
|
navigateState = state.navigateState;
|
|
92
|
-
if (key
|
|
93
|
-
|
|
94
|
-
navigationType = 'updateCurrentRoute';
|
|
98
|
+
if (key !== prevKey) {
|
|
99
|
+
navigateState = 'navigate';
|
|
95
100
|
}
|
|
96
101
|
else {
|
|
97
|
-
|
|
102
|
+
if (this.backNavigationWithinRouteType === BackNavigationType.PREFER_UPDATE) {
|
|
103
|
+
if (type === 'updateCurrentRoute' || prevType === 'updateCurrentRoute') {
|
|
104
|
+
navigationType = 'updateCurrentRoute';
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
navigationType = 'navigate';
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (this.backNavigationWithinRouteType === BackNavigationType.CURRENT_TYPE) {
|
|
111
|
+
if (isBack ? prevType === 'updateCurrentRoute' : type === 'updateCurrentRoute') {
|
|
112
|
+
navigationType = 'updateCurrentRoute';
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
navigationType = 'navigate';
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (this.backNavigationWithinRouteType === BackNavigationType.PREVIOUS_TYPE) {
|
|
119
|
+
if (isBack ? type === 'updateCurrentRoute' : type === 'updateCurrentRoute') {
|
|
120
|
+
navigationType = 'updateCurrentRoute';
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
navigationType = 'navigate';
|
|
124
|
+
}
|
|
125
|
+
}
|
|
98
126
|
}
|
|
99
127
|
}
|
|
100
128
|
else {
|
package/lib/history/client.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var base = require('./base.js');
|
|
6
|
+
var types = require('../types.js');
|
|
6
7
|
var wrapper = require('./wrapper.js');
|
|
7
8
|
|
|
8
9
|
const isHistoryState = (state) => {
|
|
@@ -59,8 +60,9 @@ class ClientHistory extends base.History {
|
|
|
59
60
|
currentIndex = 0;
|
|
60
61
|
currentState;
|
|
61
62
|
historyUnsubscribeCallback;
|
|
63
|
+
backNavigationWithinRouteType;
|
|
62
64
|
historyWrapper;
|
|
63
|
-
constructor() {
|
|
65
|
+
constructor({ backNavigationWithinRouteType, } = {}) {
|
|
64
66
|
super();
|
|
65
67
|
this.historyWrapper = wrapper.wrapHistory({
|
|
66
68
|
onNavigate: ({ url, replace, navigateState }) => {
|
|
@@ -71,6 +73,8 @@ class ClientHistory extends base.History {
|
|
|
71
73
|
});
|
|
72
74
|
},
|
|
73
75
|
});
|
|
76
|
+
this.backNavigationWithinRouteType =
|
|
77
|
+
backNavigationWithinRouteType ?? types.BackNavigationType.PREFER_UPDATE;
|
|
74
78
|
}
|
|
75
79
|
onNavigate;
|
|
76
80
|
getCurrentState() {
|
|
@@ -82,7 +86,9 @@ class ClientHistory extends base.History {
|
|
|
82
86
|
: generateState(navigation);
|
|
83
87
|
this.currentIndex = this.currentState.index;
|
|
84
88
|
this.historyWrapper.init(this.currentState);
|
|
85
|
-
this.historyUnsubscribeCallback = this.historyWrapper.subscribe(
|
|
89
|
+
this.historyUnsubscribeCallback = this.historyWrapper.subscribe(
|
|
90
|
+
// eslint-disable-next-line max-statements
|
|
91
|
+
async ({ path, state, hasUAVisualTransition }) => {
|
|
86
92
|
try {
|
|
87
93
|
let navigationType;
|
|
88
94
|
let navigateState;
|
|
@@ -93,12 +99,34 @@ class ClientHistory extends base.History {
|
|
|
93
99
|
const { key, type } = state;
|
|
94
100
|
this.currentState = state;
|
|
95
101
|
navigateState = state.navigateState;
|
|
96
|
-
if (key
|
|
97
|
-
|
|
98
|
-
navigationType = 'updateCurrentRoute';
|
|
102
|
+
if (key !== prevKey) {
|
|
103
|
+
navigateState = 'navigate';
|
|
99
104
|
}
|
|
100
105
|
else {
|
|
101
|
-
|
|
106
|
+
if (this.backNavigationWithinRouteType === types.BackNavigationType.PREFER_UPDATE) {
|
|
107
|
+
if (type === 'updateCurrentRoute' || prevType === 'updateCurrentRoute') {
|
|
108
|
+
navigationType = 'updateCurrentRoute';
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
navigationType = 'navigate';
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (this.backNavigationWithinRouteType === types.BackNavigationType.CURRENT_TYPE) {
|
|
115
|
+
if (isBack ? prevType === 'updateCurrentRoute' : type === 'updateCurrentRoute') {
|
|
116
|
+
navigationType = 'updateCurrentRoute';
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
navigationType = 'navigate';
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (this.backNavigationWithinRouteType === types.BackNavigationType.PREVIOUS_TYPE) {
|
|
123
|
+
if (isBack ? type === 'updateCurrentRoute' : type === 'updateCurrentRoute') {
|
|
124
|
+
navigationType = 'updateCurrentRoute';
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
navigationType = 'navigate';
|
|
128
|
+
}
|
|
129
|
+
}
|
|
102
130
|
}
|
|
103
131
|
}
|
|
104
132
|
else {
|
package/lib/index.browser.js
CHANGED
|
@@ -2,6 +2,7 @@ export { Router } from './router/browser.browser.js';
|
|
|
2
2
|
export { NoSpaRouter } from './router/clientNoSpa.browser.js';
|
|
3
3
|
export { AbstractRouter } from './router/abstract.browser.js';
|
|
4
4
|
export { History } from './history/base.browser.js';
|
|
5
|
+
export { BackNavigationType } from './types.browser.js';
|
|
5
6
|
export { logger, setLogger } from './logger.browser.js';
|
|
6
7
|
export { Provider } from './components/react/index.browser.js';
|
|
7
8
|
export { RouteTree } from './tree/tree.browser.js';
|
package/lib/index.es.js
CHANGED
|
@@ -2,6 +2,7 @@ export { Router } from './router/server.es.js';
|
|
|
2
2
|
export { NoSpaRouter } from './router/clientNoSpa.es.js';
|
|
3
3
|
export { AbstractRouter } from './router/abstract.es.js';
|
|
4
4
|
export { History } from './history/base.es.js';
|
|
5
|
+
export { BackNavigationType } from './types.es.js';
|
|
5
6
|
export { logger, setLogger } from './logger.es.js';
|
|
6
7
|
export { Provider } from './components/react/index.es.js';
|
|
7
8
|
export { RouteTree } from './tree/tree.es.js';
|
package/lib/index.js
CHANGED
|
@@ -6,6 +6,7 @@ var server = require('./router/server.js');
|
|
|
6
6
|
var clientNoSpa = require('./router/clientNoSpa.js');
|
|
7
7
|
var abstract = require('./router/abstract.js');
|
|
8
8
|
var base = require('./history/base.js');
|
|
9
|
+
var types = require('./types.js');
|
|
9
10
|
var logger = require('./logger.js');
|
|
10
11
|
var index = require('./components/react/index.js');
|
|
11
12
|
var tree = require('./tree/tree.js');
|
|
@@ -22,6 +23,10 @@ exports.Router = server.Router;
|
|
|
22
23
|
exports.NoSpaRouter = clientNoSpa.NoSpaRouter;
|
|
23
24
|
exports.AbstractRouter = abstract.AbstractRouter;
|
|
24
25
|
exports.History = base.History;
|
|
26
|
+
Object.defineProperty(exports, 'BackNavigationType', {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
get: function () { return types.BackNavigationType; }
|
|
29
|
+
});
|
|
25
30
|
Object.defineProperty(exports, 'logger', {
|
|
26
31
|
enumerable: true,
|
|
27
32
|
get: function () { return logger.logger; }
|
|
@@ -149,7 +149,7 @@ class AbstractRouter {
|
|
|
149
149
|
if (!prevNavigation) {
|
|
150
150
|
throw new Error('updateCurrentRoute should only be called after navigate to some route');
|
|
151
151
|
}
|
|
152
|
-
const { replace, params, navigateState } = updateRouteOptions;
|
|
152
|
+
const { replace, params, navigateState, isBack } = updateRouteOptions;
|
|
153
153
|
const { to: from, url: fromUrl } = prevNavigation;
|
|
154
154
|
const navigation = {
|
|
155
155
|
type: 'updateCurrentRoute',
|
|
@@ -162,6 +162,7 @@ class AbstractRouter {
|
|
|
162
162
|
navigateState,
|
|
163
163
|
code: updateRouteOptions.code,
|
|
164
164
|
key: this.uuid(),
|
|
165
|
+
isBack,
|
|
165
166
|
};
|
|
166
167
|
logger.debug({
|
|
167
168
|
event: 'update-current-route',
|
|
@@ -187,7 +188,7 @@ class AbstractRouter {
|
|
|
187
188
|
const resolvedUrl = this.resolveUrl(navigateOptions);
|
|
188
189
|
const { to: from, url: fromUrl } = prevNavigation ?? {};
|
|
189
190
|
const redirectFrom = redirect ? this.getCurrentRoute() : undefined;
|
|
190
|
-
|
|
191
|
+
const navigation = {
|
|
191
192
|
type: 'navigate',
|
|
192
193
|
from,
|
|
193
194
|
url: resolvedUrl,
|
|
@@ -209,10 +210,7 @@ class AbstractRouter {
|
|
|
209
210
|
await this.runHooks('beforeResolve', navigation);
|
|
210
211
|
const to = this.resolveRoute({ url: resolvedUrl, params, navigateState }, { wildcard: true });
|
|
211
212
|
if (to) {
|
|
212
|
-
navigation =
|
|
213
|
-
...navigation,
|
|
214
|
-
to,
|
|
215
|
-
};
|
|
213
|
+
navigation.to = to;
|
|
216
214
|
}
|
|
217
215
|
logger.debug({
|
|
218
216
|
event: 'navigation',
|
|
@@ -302,7 +300,7 @@ class AbstractRouter {
|
|
|
302
300
|
}
|
|
303
301
|
throw new Error('Navigation blocked');
|
|
304
302
|
}
|
|
305
|
-
cancel() { }
|
|
303
|
+
cancel(_) { }
|
|
306
304
|
normalizePathname(pathname) {
|
|
307
305
|
let normalized = pathname;
|
|
308
306
|
if (this.mergeSlashes) {
|
package/lib/router/abstract.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import type { Url } from '@tinkoff/url';
|
|
2
2
|
import type { AsyncParallelTapableHookInstance, AsyncTapableHookInstance, SyncTapableHookInstance } from '@tinkoff/hook-runner';
|
|
3
3
|
import { TapableHooks } from '@tinkoff/hook-runner';
|
|
4
|
-
import
|
|
4
|
+
import { Route, NavigateOptions, UpdateCurrentRouteOptions, Navigation, NavigationGuard, NavigationHook, NavigationSyncHook, HookName, Params, SyncHookName, HistoryOptions, RouterPlugin, BackNavigationType } from '../types';
|
|
5
5
|
import type { History } from '../history/base';
|
|
6
6
|
import type { RouteTree } from '../tree/tree';
|
|
7
7
|
export interface Options {
|
|
8
8
|
trailingSlash?: boolean;
|
|
9
9
|
mergeSlashes?: boolean;
|
|
10
10
|
enableViewTransitions?: boolean;
|
|
11
|
+
backNavigationWithinRouteType?: BackNavigationType;
|
|
11
12
|
routes?: Route[];
|
|
12
13
|
onRedirect?: NavigationHook;
|
|
13
14
|
onNotFound?: NavigationHook;
|
|
@@ -103,7 +104,7 @@ export declare abstract class AbstractRouter {
|
|
|
103
104
|
protected redirect(navigation: Navigation, target: NavigateOptions): Promise<void>;
|
|
104
105
|
protected notfound(navigation: Navigation): Promise<void>;
|
|
105
106
|
protected block(navigation: Navigation): Promise<void>;
|
|
106
|
-
cancel(): Navigation | void;
|
|
107
|
+
cancel(_?: Navigation): Navigation | void;
|
|
107
108
|
protected normalizePathname(pathname?: string): string;
|
|
108
109
|
protected resolveUrl({ url, query, params, preserveQuery, hash }: NavigateOptions): Url;
|
|
109
110
|
protected resolveRoute({ url, params, navigateState }: {
|
|
@@ -149,7 +149,7 @@ class AbstractRouter {
|
|
|
149
149
|
if (!prevNavigation) {
|
|
150
150
|
throw new Error('updateCurrentRoute should only be called after navigate to some route');
|
|
151
151
|
}
|
|
152
|
-
const { replace, params, navigateState } = updateRouteOptions;
|
|
152
|
+
const { replace, params, navigateState, isBack } = updateRouteOptions;
|
|
153
153
|
const { to: from, url: fromUrl } = prevNavigation;
|
|
154
154
|
const navigation = {
|
|
155
155
|
type: 'updateCurrentRoute',
|
|
@@ -162,6 +162,7 @@ class AbstractRouter {
|
|
|
162
162
|
navigateState,
|
|
163
163
|
code: updateRouteOptions.code,
|
|
164
164
|
key: this.uuid(),
|
|
165
|
+
isBack,
|
|
165
166
|
};
|
|
166
167
|
logger.debug({
|
|
167
168
|
event: 'update-current-route',
|
|
@@ -187,7 +188,7 @@ class AbstractRouter {
|
|
|
187
188
|
const resolvedUrl = this.resolveUrl(navigateOptions);
|
|
188
189
|
const { to: from, url: fromUrl } = prevNavigation ?? {};
|
|
189
190
|
const redirectFrom = redirect ? this.getCurrentRoute() : undefined;
|
|
190
|
-
|
|
191
|
+
const navigation = {
|
|
191
192
|
type: 'navigate',
|
|
192
193
|
from,
|
|
193
194
|
url: resolvedUrl,
|
|
@@ -209,10 +210,7 @@ class AbstractRouter {
|
|
|
209
210
|
await this.runHooks('beforeResolve', navigation);
|
|
210
211
|
const to = this.resolveRoute({ url: resolvedUrl, params, navigateState }, { wildcard: true });
|
|
211
212
|
if (to) {
|
|
212
|
-
navigation =
|
|
213
|
-
...navigation,
|
|
214
|
-
to,
|
|
215
|
-
};
|
|
213
|
+
navigation.to = to;
|
|
216
214
|
}
|
|
217
215
|
logger.debug({
|
|
218
216
|
event: 'navigation',
|
|
@@ -302,7 +300,7 @@ class AbstractRouter {
|
|
|
302
300
|
}
|
|
303
301
|
throw new Error('Navigation blocked');
|
|
304
302
|
}
|
|
305
|
-
cancel() { }
|
|
303
|
+
cancel(_) { }
|
|
306
304
|
normalizePathname(pathname) {
|
|
307
305
|
let normalized = pathname;
|
|
308
306
|
if (this.mergeSlashes) {
|
package/lib/router/abstract.js
CHANGED
|
@@ -158,7 +158,7 @@ class AbstractRouter {
|
|
|
158
158
|
if (!prevNavigation) {
|
|
159
159
|
throw new Error('updateCurrentRoute should only be called after navigate to some route');
|
|
160
160
|
}
|
|
161
|
-
const { replace, params, navigateState } = updateRouteOptions;
|
|
161
|
+
const { replace, params, navigateState, isBack } = updateRouteOptions;
|
|
162
162
|
const { to: from, url: fromUrl } = prevNavigation;
|
|
163
163
|
const navigation = {
|
|
164
164
|
type: 'updateCurrentRoute',
|
|
@@ -171,6 +171,7 @@ class AbstractRouter {
|
|
|
171
171
|
navigateState,
|
|
172
172
|
code: updateRouteOptions.code,
|
|
173
173
|
key: this.uuid(),
|
|
174
|
+
isBack,
|
|
174
175
|
};
|
|
175
176
|
logger.logger.debug({
|
|
176
177
|
event: 'update-current-route',
|
|
@@ -196,7 +197,7 @@ class AbstractRouter {
|
|
|
196
197
|
const resolvedUrl = this.resolveUrl(navigateOptions);
|
|
197
198
|
const { to: from, url: fromUrl } = prevNavigation ?? {};
|
|
198
199
|
const redirectFrom = redirect ? this.getCurrentRoute() : undefined;
|
|
199
|
-
|
|
200
|
+
const navigation = {
|
|
200
201
|
type: 'navigate',
|
|
201
202
|
from,
|
|
202
203
|
url: resolvedUrl,
|
|
@@ -218,10 +219,7 @@ class AbstractRouter {
|
|
|
218
219
|
await this.runHooks('beforeResolve', navigation);
|
|
219
220
|
const to = this.resolveRoute({ url: resolvedUrl, params, navigateState }, { wildcard: true });
|
|
220
221
|
if (to) {
|
|
221
|
-
navigation =
|
|
222
|
-
...navigation,
|
|
223
|
-
to,
|
|
224
|
-
};
|
|
222
|
+
navigation.to = to;
|
|
225
223
|
}
|
|
226
224
|
logger.logger.debug({
|
|
227
225
|
event: 'navigation',
|
|
@@ -311,7 +309,7 @@ class AbstractRouter {
|
|
|
311
309
|
}
|
|
312
310
|
throw new Error('Navigation blocked');
|
|
313
311
|
}
|
|
314
|
-
cancel() { }
|
|
312
|
+
cancel(_) { }
|
|
315
313
|
normalizePathname(pathname) {
|
|
316
314
|
let normalized = pathname;
|
|
317
315
|
if (this.mergeSlashes) {
|
|
@@ -34,8 +34,15 @@ class Router extends ClientRouter {
|
|
|
34
34
|
return this.flattenDelayedNavigation(delayedNavigation);
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
-
async run(
|
|
38
|
-
|
|
37
|
+
async run(navigation) {
|
|
38
|
+
// if navigation was cancelled before, do not run it
|
|
39
|
+
if (navigation.skipped) {
|
|
40
|
+
logger.debug({
|
|
41
|
+
event: 'run.cancel',
|
|
42
|
+
navigation,
|
|
43
|
+
});
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
39
46
|
const to = (navigation.to.redirect !== undefined
|
|
40
47
|
? this.resolve(navigation.to.redirect)?.actualPath
|
|
41
48
|
: navigation.to?.actualPath) ?? '';
|
|
@@ -91,7 +98,7 @@ class Router extends ClientRouter {
|
|
|
91
98
|
}
|
|
92
99
|
commitNavigation(navigation) {
|
|
93
100
|
// if we have parallel navigation do not update current url, as it outdated anyway
|
|
94
|
-
if (navigation.
|
|
101
|
+
if (navigation.skipped) {
|
|
95
102
|
logger.debug({
|
|
96
103
|
event: 'delay-ignore-commit',
|
|
97
104
|
navigation,
|
|
@@ -102,7 +109,7 @@ class Router extends ClientRouter {
|
|
|
102
109
|
}
|
|
103
110
|
async runGuards(navigation) {
|
|
104
111
|
// drop checking guards if we have delayed navigation
|
|
105
|
-
if (navigation.
|
|
112
|
+
if (navigation.skipped) {
|
|
106
113
|
logger.debug({
|
|
107
114
|
event: 'delay-ignore-guards',
|
|
108
115
|
navigation,
|
|
@@ -116,7 +123,7 @@ class Router extends ClientRouter {
|
|
|
116
123
|
// except only for case when current navigation already happened
|
|
117
124
|
// and we should synchronize this update with app
|
|
118
125
|
// (in case app has some logic for currently showing url on afterNavigate or afterRouteUpdate)
|
|
119
|
-
if (navigation.
|
|
126
|
+
if (navigation.skipped && this.lastNavigation !== navigation) {
|
|
120
127
|
logger.debug({
|
|
121
128
|
event: 'delay-ignore-hooks',
|
|
122
129
|
navigation,
|
|
@@ -142,7 +149,7 @@ class Router extends ClientRouter {
|
|
|
142
149
|
});
|
|
143
150
|
// set cancelled flag
|
|
144
151
|
if (this.currentNavigation) {
|
|
145
|
-
this.currentNavigation.
|
|
152
|
+
this.currentNavigation.skipped = true;
|
|
146
153
|
this.currentNavigation = null;
|
|
147
154
|
}
|
|
148
155
|
// resolve current navigation to start new navigation asap
|
|
@@ -263,17 +270,18 @@ class Router extends ClientRouter {
|
|
|
263
270
|
catch (error) { }
|
|
264
271
|
}
|
|
265
272
|
}
|
|
266
|
-
cancel() {
|
|
267
|
-
if (!this.isNavigating())
|
|
268
|
-
return;
|
|
273
|
+
cancel(navigation) {
|
|
269
274
|
logger.debug({
|
|
270
|
-
event: '
|
|
271
|
-
navigation: this.currentNavigation,
|
|
275
|
+
event: 'cancel',
|
|
276
|
+
navigation: navigation ?? this.currentNavigation,
|
|
272
277
|
});
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
278
|
+
if (navigation) {
|
|
279
|
+
navigation.skipped = true;
|
|
280
|
+
}
|
|
281
|
+
if (!navigation || navigation === this.currentNavigation) {
|
|
282
|
+
this.currentNavigation.skipped = true;
|
|
283
|
+
this.currentNavigation = null;
|
|
284
|
+
}
|
|
277
285
|
}
|
|
278
286
|
}
|
|
279
287
|
|
package/lib/router/browser.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export declare class Router extends ClientRouter {
|
|
|
10
10
|
constructor(options: Options);
|
|
11
11
|
rehydrate(navigation: Navigation): Promise<void>;
|
|
12
12
|
start(): Promise<any>;
|
|
13
|
-
protected run(
|
|
13
|
+
protected run(navigation: Navigation): Promise<any>;
|
|
14
14
|
protected delayNavigation(navigation: Navigation): Promise<void>;
|
|
15
15
|
protected commitNavigation(navigation: Navigation): void;
|
|
16
16
|
protected runGuards(navigation: Navigation): Promise<void>;
|
|
@@ -22,6 +22,6 @@ export declare class Router extends ClientRouter {
|
|
|
22
22
|
private getPrevTransition;
|
|
23
23
|
private restoreAppliedViewTransitions;
|
|
24
24
|
private saveAppliedViewTransitions;
|
|
25
|
-
cancel():
|
|
25
|
+
cancel(navigation?: Navigation): void;
|
|
26
26
|
}
|
|
27
27
|
//# sourceMappingURL=browser.d.ts.map
|
|
@@ -9,8 +9,10 @@ class ClientRouter extends AbstractRouter {
|
|
|
9
9
|
fullRehydrationInProcess = null;
|
|
10
10
|
constructor(options) {
|
|
11
11
|
super(options);
|
|
12
|
-
this.history = new ClientHistory(
|
|
13
|
-
|
|
12
|
+
this.history = new ClientHistory({
|
|
13
|
+
backNavigationWithinRouteType: options.backNavigationWithinRouteType,
|
|
14
|
+
});
|
|
15
|
+
this.history.listen(async ({ type, url, navigateState, replace, history, hasUAVisualTransition, isBack, ...rest }) => {
|
|
14
16
|
const currentUrl = this.getCurrentUrl();
|
|
15
17
|
const { pathname, query, hash } = this.resolveUrl({ url });
|
|
16
18
|
const isSameUrlNavigation = (currentUrl ? currentUrl.pathname : window.location.pathname) === pathname;
|
|
@@ -40,6 +42,7 @@ class ClientRouter extends AbstractRouter {
|
|
|
40
42
|
hash,
|
|
41
43
|
replace,
|
|
42
44
|
navigateState,
|
|
45
|
+
isBack,
|
|
43
46
|
}, { history });
|
|
44
47
|
}
|
|
45
48
|
else {
|
|
@@ -48,6 +51,7 @@ class ClientRouter extends AbstractRouter {
|
|
|
48
51
|
replace,
|
|
49
52
|
navigateState,
|
|
50
53
|
hasUAVisualTransition,
|
|
54
|
+
isBack,
|
|
51
55
|
...rest,
|
|
52
56
|
}, { history });
|
|
53
57
|
}
|
package/lib/router/client.es.js
CHANGED
|
@@ -9,8 +9,10 @@ class ClientRouter extends AbstractRouter {
|
|
|
9
9
|
fullRehydrationInProcess = null;
|
|
10
10
|
constructor(options) {
|
|
11
11
|
super(options);
|
|
12
|
-
this.history = new ClientHistory(
|
|
13
|
-
|
|
12
|
+
this.history = new ClientHistory({
|
|
13
|
+
backNavigationWithinRouteType: options.backNavigationWithinRouteType,
|
|
14
|
+
});
|
|
15
|
+
this.history.listen(async ({ type, url, navigateState, replace, history, hasUAVisualTransition, isBack, ...rest }) => {
|
|
14
16
|
const currentUrl = this.getCurrentUrl();
|
|
15
17
|
const { pathname, query, hash } = this.resolveUrl({ url });
|
|
16
18
|
const isSameUrlNavigation = (currentUrl ? currentUrl.pathname : window.location.pathname) === pathname;
|
|
@@ -40,6 +42,7 @@ class ClientRouter extends AbstractRouter {
|
|
|
40
42
|
hash,
|
|
41
43
|
replace,
|
|
42
44
|
navigateState,
|
|
45
|
+
isBack,
|
|
43
46
|
}, { history });
|
|
44
47
|
}
|
|
45
48
|
else {
|
|
@@ -48,6 +51,7 @@ class ClientRouter extends AbstractRouter {
|
|
|
48
51
|
replace,
|
|
49
52
|
navigateState,
|
|
50
53
|
hasUAVisualTransition,
|
|
54
|
+
isBack,
|
|
51
55
|
...rest,
|
|
52
56
|
}, { history });
|
|
53
57
|
}
|
package/lib/router/client.js
CHANGED
|
@@ -13,8 +13,10 @@ class ClientRouter extends abstract.AbstractRouter {
|
|
|
13
13
|
fullRehydrationInProcess = null;
|
|
14
14
|
constructor(options) {
|
|
15
15
|
super(options);
|
|
16
|
-
this.history = new client.ClientHistory(
|
|
17
|
-
|
|
16
|
+
this.history = new client.ClientHistory({
|
|
17
|
+
backNavigationWithinRouteType: options.backNavigationWithinRouteType,
|
|
18
|
+
});
|
|
19
|
+
this.history.listen(async ({ type, url, navigateState, replace, history, hasUAVisualTransition, isBack, ...rest }) => {
|
|
18
20
|
const currentUrl = this.getCurrentUrl();
|
|
19
21
|
const { pathname, query, hash } = this.resolveUrl({ url });
|
|
20
22
|
const isSameUrlNavigation = (currentUrl ? currentUrl.pathname : window.location.pathname) === pathname;
|
|
@@ -44,6 +46,7 @@ class ClientRouter extends abstract.AbstractRouter {
|
|
|
44
46
|
hash,
|
|
45
47
|
replace,
|
|
46
48
|
navigateState,
|
|
49
|
+
isBack,
|
|
47
50
|
}, { history });
|
|
48
51
|
}
|
|
49
52
|
else {
|
|
@@ -52,6 +55,7 @@ class ClientRouter extends abstract.AbstractRouter {
|
|
|
52
55
|
replace,
|
|
53
56
|
navigateState,
|
|
54
57
|
hasUAVisualTransition,
|
|
58
|
+
isBack,
|
|
55
59
|
...rest,
|
|
56
60
|
}, { history });
|
|
57
61
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Navigation type for browser "Back/Forward" within the same route
|
|
3
|
+
* prefer-update - always return via update
|
|
4
|
+
* current-type - return with current navigation type
|
|
5
|
+
* previous-type - return with the navigation type of the target route
|
|
6
|
+
*/
|
|
7
|
+
var BackNavigationType;
|
|
8
|
+
(function (BackNavigationType) {
|
|
9
|
+
BackNavigationType["CURRENT_TYPE"] = "current-type";
|
|
10
|
+
BackNavigationType["PREFER_UPDATE"] = "prefer-update";
|
|
11
|
+
BackNavigationType["PREVIOUS_TYPE"] = "previous-type";
|
|
12
|
+
})(BackNavigationType || (BackNavigationType = {}));
|
|
13
|
+
|
|
14
|
+
export { BackNavigationType };
|
package/lib/types.d.ts
CHANGED
|
@@ -24,10 +24,10 @@ export interface BaseNavigateOptions {
|
|
|
24
24
|
hash?: string;
|
|
25
25
|
navigateState?: any;
|
|
26
26
|
code?: number;
|
|
27
|
+
isBack?: boolean;
|
|
27
28
|
}
|
|
28
29
|
export interface NavigateOptions extends BaseNavigateOptions {
|
|
29
30
|
url?: string;
|
|
30
|
-
isBack?: boolean;
|
|
31
31
|
viewTransition?: boolean;
|
|
32
32
|
viewTransitionTypes?: string[];
|
|
33
33
|
hasUAVisualTransition?: boolean;
|
|
@@ -49,7 +49,6 @@ export interface Navigation {
|
|
|
49
49
|
replace?: boolean;
|
|
50
50
|
navigateState?: any;
|
|
51
51
|
history?: boolean;
|
|
52
|
-
cancelled?: boolean;
|
|
53
52
|
skipped?: boolean;
|
|
54
53
|
code?: number;
|
|
55
54
|
isBack?: boolean;
|
|
@@ -83,4 +82,15 @@ export interface HistoryState {
|
|
|
83
82
|
viewTransition?: boolean;
|
|
84
83
|
viewTransitionTypes?: string[];
|
|
85
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Navigation type for browser "Back/Forward" within the same route
|
|
87
|
+
* prefer-update - always return via update
|
|
88
|
+
* current-type - return with current navigation type
|
|
89
|
+
* previous-type - return with the navigation type of the target route
|
|
90
|
+
*/
|
|
91
|
+
export declare enum BackNavigationType {
|
|
92
|
+
CURRENT_TYPE = "current-type",
|
|
93
|
+
PREFER_UPDATE = "prefer-update",
|
|
94
|
+
PREVIOUS_TYPE = "previous-type"
|
|
95
|
+
}
|
|
86
96
|
//# sourceMappingURL=types.d.ts.map
|
package/lib/types.es.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Navigation type for browser "Back/Forward" within the same route
|
|
3
|
+
* prefer-update - always return via update
|
|
4
|
+
* current-type - return with current navigation type
|
|
5
|
+
* previous-type - return with the navigation type of the target route
|
|
6
|
+
*/
|
|
7
|
+
var BackNavigationType;
|
|
8
|
+
(function (BackNavigationType) {
|
|
9
|
+
BackNavigationType["CURRENT_TYPE"] = "current-type";
|
|
10
|
+
BackNavigationType["PREFER_UPDATE"] = "prefer-update";
|
|
11
|
+
BackNavigationType["PREVIOUS_TYPE"] = "previous-type";
|
|
12
|
+
})(BackNavigationType || (BackNavigationType = {}));
|
|
13
|
+
|
|
14
|
+
export { BackNavigationType };
|
package/lib/types.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Navigation type for browser "Back/Forward" within the same route
|
|
7
|
+
* prefer-update - always return via update
|
|
8
|
+
* current-type - return with current navigation type
|
|
9
|
+
* previous-type - return with the navigation type of the target route
|
|
10
|
+
*/
|
|
11
|
+
exports.BackNavigationType = void 0;
|
|
12
|
+
(function (BackNavigationType) {
|
|
13
|
+
BackNavigationType["CURRENT_TYPE"] = "current-type";
|
|
14
|
+
BackNavigationType["PREFER_UPDATE"] = "prefer-update";
|
|
15
|
+
BackNavigationType["PREVIOUS_TYPE"] = "previous-type";
|
|
16
|
+
})(exports.BackNavigationType || (exports.BackNavigationType = {}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tinkoff/router",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.152",
|
|
4
4
|
"description": "router",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -21,14 +21,14 @@
|
|
|
21
21
|
"watch": "tsc -w"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@tinkoff/hook-runner": "0.8.
|
|
25
|
-
"@tinkoff/react-hooks": "0.5.
|
|
26
|
-
"@tinkoff/url": "0.12.
|
|
24
|
+
"@tinkoff/hook-runner": "0.8.2",
|
|
25
|
+
"@tinkoff/react-hooks": "0.5.2",
|
|
26
|
+
"@tinkoff/url": "0.12.2",
|
|
27
27
|
"@tinkoff/utils": "^2.1.2",
|
|
28
28
|
"use-sync-external-store": "^1.4.0"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"@tramvai/core": "6.
|
|
31
|
+
"@tramvai/core": "6.77.2",
|
|
32
32
|
"react": ">=16.14.0",
|
|
33
33
|
"tslib": "^2.4.0"
|
|
34
34
|
},
|