Zuplo

Link

A navigation component that provides client-side routing capabilities for internal links and external link handling.

Import

ReactCode
import { Link } from "zudoku/components";

Usage

ReactCode
<Link to="/docs/getting-started">Get Started</Link>
ReactCode
<Link to="/profile" state={{ from: "header" }}> Profile </Link>

Replace History Entry

ReactCode
<Link to="/login" replace> Login </Link>
ReactCode
<Link to="/docs" reloadDocument> Full Page Reload </Link>

Examples

ReactCode
function Navigation() { return ( <nav> <Link to="/">Home</Link> <Link to="/docs">Documentation</Link> <Link to="/api">API Reference</Link> <Link to="/blog">Blog</Link> </nav> ); }
ReactCode
function Breadcrumbs({ path }) { return ( <div className="breadcrumbs"> <Link to="/">Home</Link> <span>/</span> <Link to="/docs">Docs</Link> <span>/</span> <span>{path}</span> </div> ); }
ReactCode
function DocsList({ docs }) { return ( <ul> {docs.map((doc) => ( <li key={doc.id}> <Link to={`/docs/${doc.slug}`}>{doc.title}</Link> </li> ))} </ul> ); }

Conditional Linking

ReactCode
function ConditionalLink({ to, disabled, children }) { if (disabled) { return <span className="disabled-link">{children}</span>; } return <Link to={to}>{children}</Link>; }
ReactCode
// Relative to current route <Link to="../parent-page">Up one level</Link> // Relative to path <Link to="./sibling-page" relative="path"> Sibling page </Link>
ReactCode
<Link to="/absolute/path">Absolute Path</Link>

Query Parameters

ReactCode
<Link to="/search?q=react&type=docs">Search Results</Link>
ReactCode
<Link to="/docs/api#authentication">Authentication Section</Link>

Advanced Usage

With Custom Styling

ReactCode
<Link to="/important-page" className="text-blue-600 hover:text-blue-800 underline"> Important Page </Link>

Programmatic Navigation

ReactCode
import { useNavigate } from "react-router"; function MyComponent() { const navigate = useNavigate(); const handleClick = () => { // Perform some logic navigate("/next-page"); }; return ( <div> <Link to="/direct-link">Direct Link</Link> <button onClick={handleClick}>Programmatic Navigation</button> </div> ); }
ReactCode
function DeleteLink({ itemId }) { const handleClick = (e) => { if (!confirm("Are you sure you want to delete this item?")) { e.preventDefault(); } }; return ( <Link to={`/items/${itemId}/delete`} onClick={handleClick} className="text-red-600"> Delete Item </Link> ); }

Integration with Button

Use the Link component with the Button component's asChild prop:

ReactCode
<Button asChild variant="outline"> <Link to="/action">Perform Action</Link> </Button>

Accessibility

The Link component maintains accessibility best practices:

  • Proper focus management
  • Keyboard navigation support
  • Screen reader compatibility
  • Semantic HTML structure
ReactCode
<Link to="/help" aria-label="Get help and support"> Help </Link>

Performance

  • Client-side routing: No full page reloads for internal navigation
  • Prefetching: Intelligent prefetching of linked resources
  • View transitions: Smooth transitions between pages (when supported)

Notes

The Link component is optimized for internal navigation and provides the best user experience for single-page application routing.

For external links, use a regular <a> tag instead of the Link component to ensure proper external navigation behavior.

When using reloadDocument, the link will perform a full page reload, which may impact performance and user experience.

Last modified on