@tinkoff/router 0.1.68 → 0.1.71
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/README.md +14 -3
- package/lib/index.browser.js +12 -3
- package/lib/index.es.js +3 -3
- package/lib/index.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -60,8 +60,12 @@ export const myGuard: NavigationGuard = async ({ to }) => {
|
|
|
60
60
|
return false; // block this transition
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
if (to.config.redirect) {
|
|
64
|
-
return
|
|
63
|
+
if (typeof to.config.redirect === 'string') {
|
|
64
|
+
return to.config.redirect; // call a redirect to the specified page
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (typeof to.config.needAuth && !isAuth()) {
|
|
68
|
+
return { url: '/login/', code: '302' }; // redirect to page with NavigateOptions
|
|
65
69
|
}
|
|
66
70
|
|
|
67
71
|
// if nothing is returned, the transition will be performed as usual
|
|
@@ -83,7 +87,7 @@ The behaviour of routing depends on the result of executing guards functions and
|
|
|
83
87
|
- if all of the guards returns `undefined` than navigation will continue executing
|
|
84
88
|
- if any of the guards returns `false` than navigation is getting blocked and next action differs on server and client
|
|
85
89
|
- if any of the guards returns `string` it is considered as url to which redirect should be happen
|
|
86
|
-
- if any of the guards returns `NavigateOptions` interface, `url` property from it is considered as url to which redirect should be happen
|
|
90
|
+
- if any of the guards returns [`NavigateOptions`](#navigateoptions) interface, `url` property from it is considered as url to which redirect should be happen
|
|
87
91
|
|
|
88
92
|
### Transitions hooks
|
|
89
93
|
|
|
@@ -172,6 +176,13 @@ router.updateCurrentRoute({ query: { a: '1' } });
|
|
|
172
176
|
2. `change`
|
|
173
177
|
3. `afterUpdateCurrent`
|
|
174
178
|
|
|
179
|
+
### NavigateOptions
|
|
180
|
+
|
|
181
|
+
Object that allows to specify transition options both to [navigate](#navigate) and [updateCurrentRoute](#updatecurrentroute) transitions
|
|
182
|
+
|
|
183
|
+
- `code` - redirect code that is returned on server in case of redirects
|
|
184
|
+
- `navigateState` - any additional data that is stored with route
|
|
185
|
+
|
|
175
186
|
### Working with query
|
|
176
187
|
|
|
177
188
|
#### query option
|
package/lib/index.browser.js
CHANGED
|
@@ -7,8 +7,8 @@ import noop from '@tinkoff/utils/function/noop';
|
|
|
7
7
|
import each from '@tinkoff/utils/array/each';
|
|
8
8
|
import find from '@tinkoff/utils/array/find';
|
|
9
9
|
import findIndex from '@tinkoff/utils/array/findIndex';
|
|
10
|
-
import React, { createContext, useState,
|
|
11
|
-
import { useShallowEqual } from '@tinkoff/react-hooks';
|
|
10
|
+
import React, { createContext, useState, useContext, useCallback, isValidElement, cloneElement } from 'react';
|
|
11
|
+
import { useIsomorphicLayoutEffect, useShallowEqual } from '@tinkoff/react-hooks';
|
|
12
12
|
|
|
13
13
|
const PARAMETER_DELIMITER = ':';
|
|
14
14
|
const WILDCARD_REGEXP = /\*/;
|
|
@@ -953,6 +953,15 @@ class Router extends ClientRouter {
|
|
|
953
953
|
if (this.currentNavigation) {
|
|
954
954
|
return this.delayNavigation(navigation);
|
|
955
955
|
}
|
|
956
|
+
// ignore previous navigations that were put in delayedNavigation as we have more fresh navigation to execute
|
|
957
|
+
if (this.delayedNavigation) {
|
|
958
|
+
logger.info({
|
|
959
|
+
event: 'delay-navigation-drop',
|
|
960
|
+
delayedNavigation: this.delayedNavigation,
|
|
961
|
+
navigation,
|
|
962
|
+
});
|
|
963
|
+
this.delayedNavigation = null;
|
|
964
|
+
}
|
|
956
965
|
return this.flattenDelayedNavigation(navigation);
|
|
957
966
|
}
|
|
958
967
|
delayNavigation(navigation) {
|
|
@@ -1100,7 +1109,7 @@ const Provider = ({ router, children, }) => {
|
|
|
1100
1109
|
route: router.getCurrentRoute(),
|
|
1101
1110
|
url: router.getCurrentUrl(),
|
|
1102
1111
|
});
|
|
1103
|
-
|
|
1112
|
+
useIsomorphicLayoutEffect(() => {
|
|
1104
1113
|
return router.registerSyncHook('change', ({ to, url }) => {
|
|
1105
1114
|
setState({ route: to, url });
|
|
1106
1115
|
});
|
package/lib/index.es.js
CHANGED
|
@@ -7,8 +7,8 @@ import noop from '@tinkoff/utils/function/noop';
|
|
|
7
7
|
import each from '@tinkoff/utils/array/each';
|
|
8
8
|
import find from '@tinkoff/utils/array/find';
|
|
9
9
|
import findIndex from '@tinkoff/utils/array/findIndex';
|
|
10
|
-
import React, { createContext, useState,
|
|
11
|
-
import { useShallowEqual } from '@tinkoff/react-hooks';
|
|
10
|
+
import React, { createContext, useState, useContext, useCallback, isValidElement, cloneElement } from 'react';
|
|
11
|
+
import { useIsomorphicLayoutEffect, useShallowEqual } from '@tinkoff/react-hooks';
|
|
12
12
|
|
|
13
13
|
const PARAMETER_DELIMITER = ':';
|
|
14
14
|
const WILDCARD_REGEXP = /\*/;
|
|
@@ -1037,7 +1037,7 @@ const Provider = ({ router, children, }) => {
|
|
|
1037
1037
|
route: router.getCurrentRoute(),
|
|
1038
1038
|
url: router.getCurrentUrl(),
|
|
1039
1039
|
});
|
|
1040
|
-
|
|
1040
|
+
useIsomorphicLayoutEffect(() => {
|
|
1041
1041
|
return router.registerSyncHook('change', ({ to, url }) => {
|
|
1042
1042
|
setState({ route: to, url });
|
|
1043
1043
|
});
|
package/lib/index.js
CHANGED
|
@@ -1053,7 +1053,7 @@ const Provider = ({ router, children, }) => {
|
|
|
1053
1053
|
route: router.getCurrentRoute(),
|
|
1054
1054
|
url: router.getCurrentUrl(),
|
|
1055
1055
|
});
|
|
1056
|
-
|
|
1056
|
+
reactHooks.useIsomorphicLayoutEffect(() => {
|
|
1057
1057
|
return router.registerSyncHook('change', ({ to, url }) => {
|
|
1058
1058
|
setState({ route: to, url });
|
|
1059
1059
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tinkoff/router",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.71",
|
|
4
4
|
"description": "router",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"build-for-publish": "true"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@tinkoff/react-hooks": "0.0.
|
|
25
|
+
"@tinkoff/react-hooks": "0.0.24",
|
|
26
26
|
"@tinkoff/url": "0.7.37",
|
|
27
27
|
"@tinkoff/utils": "^2.1.2"
|
|
28
28
|
},
|