@tinkoff/router 0.2.3 → 0.2.5
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 +0 -23
- package/lib/components/react/index.d.ts +0 -1
- package/lib/history/base.d.ts +1 -1
- package/lib/index.browser.js +2 -30
- package/lib/index.es.js +2 -30
- package/lib/index.js +0 -29
- package/lib/logger.d.ts +1 -1
- package/lib/tree/types.d.ts +1 -1
- package/lib/types.d.ts +8 -8
- package/package.json +3 -3
- package/lib/components/react/link.d.ts +0 -14
package/README.md
CHANGED
|
@@ -273,29 +273,6 @@ export const Cmp = () => {
|
|
|
273
273
|
};
|
|
274
274
|
```
|
|
275
275
|
|
|
276
|
-
#### Link
|
|
277
|
-
|
|
278
|
-
A wrapper for a react component that makes it clickable
|
|
279
|
-
|
|
280
|
-
> If the react component is passed to the Link as children, then this passed component will be rendered and the `href`, `onClick` props will be passed as props to that component and they should be used to make the navigation. Otherwise, the `<a>` tag will be rendered with children as a child.
|
|
281
|
-
|
|
282
|
-
```ts
|
|
283
|
-
import { Link } from '@tinkoff/router';
|
|
284
|
-
import CustomLink from '@custom-scope/link';
|
|
285
|
-
|
|
286
|
-
export const Component = () => {
|
|
287
|
-
return (
|
|
288
|
-
<Link url="/test/">
|
|
289
|
-
<CustomLink />
|
|
290
|
-
</Link>
|
|
291
|
-
);
|
|
292
|
-
};
|
|
293
|
-
|
|
294
|
-
export const WrapLink = () => {
|
|
295
|
-
return <Link url="/test/">Click me</Link>;
|
|
296
|
-
};
|
|
297
|
-
```
|
|
298
|
-
|
|
299
276
|
## How to
|
|
300
277
|
|
|
301
278
|
### Load route config from external api
|
package/lib/history/base.d.ts
CHANGED
package/lib/index.browser.js
CHANGED
|
@@ -9,7 +9,7 @@ import find from '@tinkoff/utils/array/find';
|
|
|
9
9
|
import findIndex from '@tinkoff/utils/array/findIndex';
|
|
10
10
|
import { jsx } from 'react/jsx-runtime';
|
|
11
11
|
import { useSyncExternalStore } from 'use-sync-external-store/shim';
|
|
12
|
-
import { createContext, useContext, useCallback
|
|
12
|
+
import { createContext, useContext, useCallback } from 'react';
|
|
13
13
|
import { useShallowEqual } from '@tinkoff/react-hooks';
|
|
14
14
|
|
|
15
15
|
const PARAMETER_DELIMITER = ':';
|
|
@@ -1166,32 +1166,4 @@ const useNavigate = (rootOptions) => {
|
|
|
1166
1166
|
}, [rootOpts, router]);
|
|
1167
1167
|
};
|
|
1168
1168
|
|
|
1169
|
-
|
|
1170
|
-
const { children, onClick, url, query, replace, target, navigateOptions, ...otherProps } = props;
|
|
1171
|
-
const navigate = useNavigate({ url, query, replace, ...navigateOptions });
|
|
1172
|
-
const handleClick = useCallback((event) => {
|
|
1173
|
-
// ignores the navigation when clicked using right mouse button or
|
|
1174
|
-
// by holding a special modifier key: ctrl, command, win, alt, shift
|
|
1175
|
-
if (target ||
|
|
1176
|
-
event.ctrlKey ||
|
|
1177
|
-
event.metaKey ||
|
|
1178
|
-
event.altKey ||
|
|
1179
|
-
event.shiftKey ||
|
|
1180
|
-
event.button !== 0) {
|
|
1181
|
-
return;
|
|
1182
|
-
}
|
|
1183
|
-
event.preventDefault();
|
|
1184
|
-
navigate();
|
|
1185
|
-
onClick && onClick(event);
|
|
1186
|
-
}, [navigate, target, onClick]);
|
|
1187
|
-
const extraProps = { href: url, onClick: handleClick, target };
|
|
1188
|
-
if (isValidElement(children)) {
|
|
1189
|
-
return cloneElement(children, extraProps);
|
|
1190
|
-
}
|
|
1191
|
-
return (
|
|
1192
|
-
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
1193
|
-
jsx("a", { ...otherProps, ...extraProps, children: children }));
|
|
1194
|
-
}
|
|
1195
|
-
Link.displayName = 'Link';
|
|
1196
|
-
|
|
1197
|
-
export { AbstractRouter, History, Link, NoSpaRouter, Provider, RouteTree, Router, getParts, isHistoryFallback, isParameterized, isWildcard, logger, makePath, parse, setLogger, useNavigate, useRoute, useRouter, useUrl };
|
|
1169
|
+
export { AbstractRouter, History, NoSpaRouter, Provider, RouteTree, Router, getParts, isHistoryFallback, isParameterized, isWildcard, logger, makePath, parse, setLogger, useNavigate, useRoute, useRouter, useUrl };
|
package/lib/index.es.js
CHANGED
|
@@ -9,7 +9,7 @@ import find from '@tinkoff/utils/array/find';
|
|
|
9
9
|
import findIndex from '@tinkoff/utils/array/findIndex';
|
|
10
10
|
import { jsx } from 'react/jsx-runtime';
|
|
11
11
|
import { useSyncExternalStore } from 'use-sync-external-store/shim';
|
|
12
|
-
import { createContext, useContext, useCallback
|
|
12
|
+
import { createContext, useContext, useCallback } from 'react';
|
|
13
13
|
import { useShallowEqual } from '@tinkoff/react-hooks';
|
|
14
14
|
|
|
15
15
|
const PARAMETER_DELIMITER = ':';
|
|
@@ -1094,32 +1094,4 @@ const useNavigate = (rootOptions) => {
|
|
|
1094
1094
|
}, [rootOpts, router]);
|
|
1095
1095
|
};
|
|
1096
1096
|
|
|
1097
|
-
|
|
1098
|
-
const { children, onClick, url, query, replace, target, navigateOptions, ...otherProps } = props;
|
|
1099
|
-
const navigate = useNavigate({ url, query, replace, ...navigateOptions });
|
|
1100
|
-
const handleClick = useCallback((event) => {
|
|
1101
|
-
// ignores the navigation when clicked using right mouse button or
|
|
1102
|
-
// by holding a special modifier key: ctrl, command, win, alt, shift
|
|
1103
|
-
if (target ||
|
|
1104
|
-
event.ctrlKey ||
|
|
1105
|
-
event.metaKey ||
|
|
1106
|
-
event.altKey ||
|
|
1107
|
-
event.shiftKey ||
|
|
1108
|
-
event.button !== 0) {
|
|
1109
|
-
return;
|
|
1110
|
-
}
|
|
1111
|
-
event.preventDefault();
|
|
1112
|
-
navigate();
|
|
1113
|
-
onClick && onClick(event);
|
|
1114
|
-
}, [navigate, target, onClick]);
|
|
1115
|
-
const extraProps = { href: url, onClick: handleClick, target };
|
|
1116
|
-
if (isValidElement(children)) {
|
|
1117
|
-
return cloneElement(children, extraProps);
|
|
1118
|
-
}
|
|
1119
|
-
return (
|
|
1120
|
-
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
1121
|
-
jsx("a", { ...otherProps, ...extraProps, children: children }));
|
|
1122
|
-
}
|
|
1123
|
-
Link.displayName = 'Link';
|
|
1124
|
-
|
|
1125
|
-
export { AbstractRouter, History, Link, NoSpaRouter, Provider, RouteTree, Router, getParts, isHistoryFallback, isParameterized, isWildcard, logger, makePath, parse, setLogger, useNavigate, useRoute, useRouter, useUrl };
|
|
1097
|
+
export { AbstractRouter, History, NoSpaRouter, Provider, RouteTree, Router, getParts, isHistoryFallback, isParameterized, isWildcard, logger, makePath, parse, setLogger, useNavigate, useRoute, useRouter, useUrl };
|
package/lib/index.js
CHANGED
|
@@ -1109,37 +1109,8 @@ const useNavigate = (rootOptions) => {
|
|
|
1109
1109
|
}, [rootOpts, router]);
|
|
1110
1110
|
};
|
|
1111
1111
|
|
|
1112
|
-
function Link(props) {
|
|
1113
|
-
const { children, onClick, url, query, replace, target, navigateOptions, ...otherProps } = props;
|
|
1114
|
-
const navigate = useNavigate({ url, query, replace, ...navigateOptions });
|
|
1115
|
-
const handleClick = react.useCallback((event) => {
|
|
1116
|
-
// ignores the navigation when clicked using right mouse button or
|
|
1117
|
-
// by holding a special modifier key: ctrl, command, win, alt, shift
|
|
1118
|
-
if (target ||
|
|
1119
|
-
event.ctrlKey ||
|
|
1120
|
-
event.metaKey ||
|
|
1121
|
-
event.altKey ||
|
|
1122
|
-
event.shiftKey ||
|
|
1123
|
-
event.button !== 0) {
|
|
1124
|
-
return;
|
|
1125
|
-
}
|
|
1126
|
-
event.preventDefault();
|
|
1127
|
-
navigate();
|
|
1128
|
-
onClick && onClick(event);
|
|
1129
|
-
}, [navigate, target, onClick]);
|
|
1130
|
-
const extraProps = { href: url, onClick: handleClick, target };
|
|
1131
|
-
if (react.isValidElement(children)) {
|
|
1132
|
-
return react.cloneElement(children, extraProps);
|
|
1133
|
-
}
|
|
1134
|
-
return (
|
|
1135
|
-
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
1136
|
-
jsxRuntime.jsx("a", { ...otherProps, ...extraProps, children: children }));
|
|
1137
|
-
}
|
|
1138
|
-
Link.displayName = 'Link';
|
|
1139
|
-
|
|
1140
1112
|
exports.AbstractRouter = AbstractRouter;
|
|
1141
1113
|
exports.History = History;
|
|
1142
|
-
exports.Link = Link;
|
|
1143
1114
|
exports.NoSpaRouter = NoSpaRouter;
|
|
1144
1115
|
exports.Provider = Provider;
|
|
1145
1116
|
exports.RouteTree = RouteTree;
|
package/lib/logger.d.ts
CHANGED
package/lib/tree/types.d.ts
CHANGED
package/lib/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Url, Query } from '@tinkoff/url';
|
|
2
|
-
export
|
|
2
|
+
export type Params = Record<string, string>;
|
|
3
3
|
export interface Route {
|
|
4
4
|
name: string;
|
|
5
5
|
path: string;
|
|
@@ -24,11 +24,11 @@ export interface BaseNavigateOptions {
|
|
|
24
24
|
export interface NavigateOptions extends BaseNavigateOptions {
|
|
25
25
|
url?: string;
|
|
26
26
|
}
|
|
27
|
-
export
|
|
27
|
+
export type UpdateCurrentRouteOptions = BaseNavigateOptions;
|
|
28
28
|
export interface HistoryOptions {
|
|
29
29
|
historyFallback: string;
|
|
30
30
|
}
|
|
31
|
-
export
|
|
31
|
+
export type NavigationType = 'navigate' | 'updateCurrentRoute';
|
|
32
32
|
export interface Navigation {
|
|
33
33
|
type: NavigationType;
|
|
34
34
|
from?: NavigationRoute;
|
|
@@ -43,8 +43,8 @@ export interface Navigation {
|
|
|
43
43
|
redirect?: boolean;
|
|
44
44
|
redirectFrom?: NavigationRoute;
|
|
45
45
|
}
|
|
46
|
-
export
|
|
47
|
-
export
|
|
48
|
-
export
|
|
49
|
-
export
|
|
50
|
-
export
|
|
46
|
+
export type NavigationGuard = (navigation: Navigation) => Promise<void | NavigateOptions | string | boolean>;
|
|
47
|
+
export type NavigationHook = (navigation: Navigation) => Promise<void>;
|
|
48
|
+
export type NavigationSyncHook = (navigation: Navigation) => void;
|
|
49
|
+
export type HookName = 'beforeResolve' | 'beforeNavigate' | 'afterNavigate' | 'beforeUpdateCurrent' | 'afterUpdateCurrent';
|
|
50
|
+
export type SyncHookName = 'change';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tinkoff/router",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"description": "router",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"build-for-publish": "true"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@tinkoff/react-hooks": "0.1.
|
|
26
|
-
"@tinkoff/url": "0.8.
|
|
25
|
+
"@tinkoff/react-hooks": "0.1.4",
|
|
26
|
+
"@tinkoff/url": "0.8.4",
|
|
27
27
|
"@tinkoff/utils": "^2.1.2",
|
|
28
28
|
"use-sync-external-store": "^1.2.0"
|
|
29
29
|
},
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
interface Props {
|
|
2
|
-
children?: any;
|
|
3
|
-
url: string;
|
|
4
|
-
query?: Record<string, string>;
|
|
5
|
-
replace?: boolean;
|
|
6
|
-
target?: string;
|
|
7
|
-
onClick?: Function;
|
|
8
|
-
navigateOptions?: Record<string, any>;
|
|
9
|
-
}
|
|
10
|
-
declare function Link(props: Props): JSX.Element;
|
|
11
|
-
declare namespace Link {
|
|
12
|
-
var displayName: string;
|
|
13
|
-
}
|
|
14
|
-
export { Link };
|