Directory
- Welcome
Link Component
The Link component enhances your website’s navigation by automatically handling both internal and external URLs. It provides built-in security features, consistent URL formatting, and content collection link validation.
Key Features
-
Smart URL Processing: Automatic HTTPS upgrade and trailing slash handling
-
Security Features: Built-in protection for external links
-
Content Collection Validation: Automatic verification of content collection URLs
Basic Usage
Create links with automatic handling of internal and external URLs:
---import A from '@/components/NST-components/UI/link/Link.astro';---
<A href="https://example.com">External Link</A><A href="/">Internal Link</A>
Smart Features
URL Processing
The component automatically handles various URL scenarios:
<!-- HTTP to HTTPS conversion --><A href="http://example.com">Converts to HTTPS</A>
<!-- Trailing slash addition -->
<A href="/about">Adds trailing slash</A>
<!-- Hash links remain unchanged -->
<A href="#section">Hash link</A>
Security Enhancements
External links receive automatic security attributes:
<!-- External link with security attributes --><A href="https://external-site.com"> <!-- Outputs: --> <!-- target="_blank" rel="noopener noreferrer" --></A>
Content Collection Validation
The component validates content collection URLs against published content. Very useful for SEO as it will render as text if the content collection is not published, and when it is published the link will work:
<!-- Valid blog post link --><A href="/blog/existing-post">Links to post</A>
<!-- Invalid blog post link -->
<A href="/blog/not-published">Renders as text</A>
Limited Time Launch Sale
Get our secure and SEO-friendly starter template with built-in link handling. Start building your website faster!
GET 60% OFF!