jordy 0.14.2 → 0.14.3
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/esm5/hooks/useNavigate.js +12 -10
- package/package.json +1 -1
|
@@ -11,11 +11,19 @@ function instanceOfSearchParams(to) {
|
|
|
11
11
|
function isMergeQueries(option) {
|
|
12
12
|
return isUndefined(option) || (option && option['merge'] === true);
|
|
13
13
|
}
|
|
14
|
+
function refineQueries(queries) {
|
|
15
|
+
return Object.entries(queries).reduce(function (acc, _a) {
|
|
16
|
+
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
17
|
+
if (!isNullable(value) && value !== '') {
|
|
18
|
+
acc[key] = value;
|
|
19
|
+
}
|
|
20
|
+
return acc;
|
|
21
|
+
}, {});
|
|
22
|
+
}
|
|
14
23
|
export function useNavigate() {
|
|
15
24
|
var _a = __read(useSearchParams(), 2), currentSearchParams = _a[0], setSearchParams = _a[1];
|
|
16
25
|
var navigate = useRcNavigate();
|
|
17
26
|
var navigation = useCallback(function (to, option) {
|
|
18
|
-
var _a;
|
|
19
27
|
if (typeof to === 'number') {
|
|
20
28
|
return navigate(to);
|
|
21
29
|
}
|
|
@@ -26,22 +34,16 @@ export function useNavigate() {
|
|
|
26
34
|
return navigate(to, option);
|
|
27
35
|
}
|
|
28
36
|
if (instanceOfSearchParams(to)) {
|
|
29
|
-
var newQueries = {};
|
|
30
|
-
for (var key in to) {
|
|
31
|
-
if (isNullable(to[key]) || to[key] === '') {
|
|
32
|
-
continue;
|
|
33
|
-
}
|
|
34
|
-
newQueries = __assign(__assign({}, newQueries), (_a = {}, _a[key] = to[key], _a));
|
|
35
|
-
}
|
|
36
37
|
if (isMergeQueries(option)) {
|
|
37
38
|
var currentQueries = __spreadArray([], __read(currentSearchParams), false).reduce(function (acc, _a) {
|
|
38
39
|
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
39
40
|
acc[key] = value;
|
|
40
41
|
return acc;
|
|
41
42
|
}, {});
|
|
42
|
-
|
|
43
|
+
var mergeQueries = __assign(__assign({}, currentQueries), to);
|
|
44
|
+
return setSearchParams(refineQueries(mergeQueries), option);
|
|
43
45
|
}
|
|
44
|
-
return setSearchParams(
|
|
46
|
+
return setSearchParams(refineQueries(to), option);
|
|
45
47
|
}
|
|
46
48
|
return navigate(to, option);
|
|
47
49
|
}, [currentSearchParams, navigate, setSearchParams]);
|