Link
Documentation and examples for the Link component.
When To Use
- When you need to provide hyperlinks to other pages within your application or to external resources.
- When you need a unified component that seamlessly handles type-safe internal routing (via astro-typesafe-routes) and standard external anchor tags.
Variants
Disabled Link
To visually disable a link, apply Tailwind utility classes like pointer-events-none and opacity-50 since standard HTML <a> elements do not natively support the disabled attribute.
<Link to='/' class='text-blue-600 pointer-events-none opacity-50'>Disabled Link</Link> Button Link
When a link needs to look like a button (e.g., call-to-action links), apply button-equivalent Tailwind classes or import and apply the button variants directly to the <Link> component instead of nesting a <Button> inside it.
---
import { buttonVariants } from '@/components/general/Button.astro';
---
<Link href='https://example.com' class={buttonVariants({ variant: 'primary' })}>Button Link</Link>
<Link href='https://example.com' class={buttonVariants({ variant: 'outline' })}>Outline Link</Link> Example Usage
<Link to='/' class='text-blue-600 hover:underline'>Internal Typesafe Link (to)</Link>
<Link href='https://example.com' class='text-blue-600 hover:underline'>External Link (href)</Link> How to Use
The Link component provides a unified interface for both internal routing and external links. Internal links utilize astro-typesafe-routes to provide auto-completion and ensure routes exist. External links fall back to standard anchor tags.
Internal Links (Typesafe)
Use the to prop for internal navigation. This enables autocompletion for your defined routes.
---
import Link from '@/components/general/Link.astro';
---
<Link to="/[lang]/docs" params={{ lang }} class="text-blue-600 hover:underline">
Go to Docs
</Link> External Links
Use the href prop for standard external URLs.
---
import Link from '@/components/general/Link.astro';
---
<Link href="https://github.com" target="_blank" rel="noopener noreferrer" class="text-blue-600 hover:underline">
GitHub
</Link> API
| Property | Description | Type | Default |
|---|---|---|---|
| to | Internal route path for type-safe routing. | any | - |
| params | Route parameters for type-safe routing. | Record<string, string> | - |
| href | Standard external URL. | string | - |