Link
A versatile link component that supports both internal and external navigation with active state detection and various styling options.
Overview
The Link component is a fundamental navigation element that enhances the standard HTML anchor with features like active state detection, external link handling, and various styling options. It's built on top of Nuxt's routing system while maintaining accessibility and user experience.
Features
- Multiple variants (solid, soft, subtle, ghost, link)
- Active state detection for current routes
- Support for external and internal links
- Exact matching options for routes
- Disabled state support
- Accessible by default
- Customizable styling
Usage
Basic Link
The simplest way to use the link is with text content:
Home
External Links
Links automatically handle external URLs with appropriate attributes:
Nuxt Website
Active State
Links can show an active state when matching the current route:
Active Link
Regular Link
Exact Matching
Control how the active state is determined:
Exact Match
Partial Match
Disabled State
Links can be disabled to prevent navigation:
Disabled Link
Props
The target route path for internal navigation.
The URL for external links.
Manually set the active state of the link.
When true, the active state requires an exact route match.
Disables the link, preventing navigation.
Specifies where to open the linked document.
Specifies the relationship between the current document and the linked document.
Forces the link to be treated as an external link.
Slots
The default slot for link content.
Best Practices
- Use appropriate props for different scenarios:
- Use
tofor internal navigation within your application - Use
hreffor external links - Add
target="_blank"for links that open in new tabs
- Use
- Implement proper active states:
- Use
exactwhen you need precise route matching - Consider the hierarchy of your routes when setting up active states
- Use
- Maintain accessibility:
- Provide clear and descriptive link text
- Use appropriate ARIA attributes when needed
- Ensure sufficient color contrast for active and inactive states
- Security considerations:
- Add appropriate
relattributes for external links - Use
rel="noopener noreferrer"when opening links in new tabs
- Add appropriate
- Handle edge cases:
- Implement proper disabled states when needed
- Consider loading states for async navigation
- Handle external links appropriately with the
isExternalprop