Open http external links in new window by default

Signed-off-by: Deepak Bhardwaj <deepak.bhardwaj@outlook.com>
This commit is contained in:
Deepak Bhardwaj
2021-07-01 19:39:37 +05:30
parent 80b42d7137
commit 9bb672c06a
@@ -37,12 +37,14 @@ export type LinkProps = MaterialLinkProps &
*/
export const Link = React.forwardRef<any, LinkProps>((props, ref) => {
const to = String(props.to);
return isExternalUri(to) ? (
const external = isExternalUri(to);
const newWindow = external && !!/^https?:/.exec(to);
return external ? (
// External links
<MaterialLink
ref={ref}
href={to}
{...{ target: '_blank', rel: 'noopener' }}
{...(newWindow ? { target: '_blank', rel: 'noopener' } : {})}
{...props}
/>
) : (