forked from codesandbox/codesandbox-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLink.tsx
More file actions
30 lines (28 loc) · 670 Bytes
/
Link.tsx
File metadata and controls
30 lines (28 loc) · 670 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import React from 'react';
import { Link as RouterLink } from 'react-router-dom';
export interface ILinkProps {
to?: any;
external?: boolean;
onClick?: React.MouseEventHandler<HTMLAnchorElement>;
}
export const Link: React.FC<ILinkProps> = React.forwardRef<
HTMLAnchorElement,
ILinkProps
>(({ to = undefined, external = false, onClick, children, ...props }, ref) =>
external ? (
<a
ref={ref}
{...props}
href={to as string}
onClick={onClick}
target="_blank"
rel="noopener noreferrer"
>
{children}
</a>
) : (
<RouterLink innerRef={ref} to={to} {...props}>
{children}
</RouterLink>
)
);