fix: stop link component opening internal page in new tab
All checks were successful
Docker / build-and-push-image (push) Successful in 1m16s
All checks were successful
Docker / build-and-push-image (push) Successful in 1m16s
This commit is contained in:
parent
9346a78c27
commit
237eeb4cac
5 changed files with 166 additions and 384 deletions
|
@ -3,13 +3,21 @@ import type { HTMLAttributes } from "astro/types";
|
|||
|
||||
interface Props extends HTMLAttributes<"a"> {
|
||||
href: string;
|
||||
external?: boolean;
|
||||
class?: string;
|
||||
}
|
||||
|
||||
const { href, external = true, ...rest } = Astro.props;
|
||||
const { href, ...rest } = Astro.props;
|
||||
|
||||
const isExternal =
|
||||
/^(https?:)?\/\//.test(href) ||
|
||||
href.startsWith("mailto:") ||
|
||||
href.startsWith("tel:");
|
||||
---
|
||||
|
||||
<a href={href} target={external ? "_blank" : "_self"} {...rest}>
|
||||
<a
|
||||
href={href}
|
||||
target={isExternal ? "_blank" : "_self"}
|
||||
rel={isExternal ? "noopener noreferrer" : undefined}
|
||||
{...rest}
|
||||
>
|
||||
<slot />
|
||||
</a>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue