Merge pull request #6244 from deepak-bhardwaj-ps/explorer-external-tools

feat: open external tools in new tab
This commit is contained in:
Fredrik Adelöw
2021-07-02 10:03:29 +02:00
committed by GitHub
4 changed files with 19 additions and 4 deletions
@@ -37,9 +37,16 @@ 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} {...props} />
<MaterialLink
ref={ref}
href={to}
{...(newWindow ? { target: '_blank', rel: 'noopener' } : {})}
{...props}
/>
) : (
// Interact with React Router for internal links
<MaterialLink ref={ref} component={RouterLink} {...props} />