# Next.js link

Next.js link is a neobrutalist React component from Cruise UI. next/link wrapped in a "use client" file, for the linkComponent prop of the Dashboard layout, Footer, Auth card and Dropdown menu, so their links navigate client-side. Works when passed from a Server Component, which next/link's Link itself can't be.

Install (with the @cruiseui registry in components.json, see Installation):

```bash
npx shadcn@latest add @cruiseui/cruise-next-link
```

Import: `import { CruiseNextLink } from "@/components/cruise/next-link";`

## When to use

A Next.js app using the Dashboard layout, Footer, Auth card or Dropdown menu.

## When not to

Other frameworks: pass your router's link component (or leave the default <a>).

## Usage

- `<CruiseDashboardLayout linkComponent={CruiseNextLink} … />` in app/<section>/layout.tsx. Passing `Link` from next/link directly fails in a Server Component ("Functions cannot be passed directly to Client Components"); this wrapper is a client reference, so it works there and in client components.
- It takes every next/link prop (prefetch, replace, scroll…).

## Example (React)

```tsx
import { CruiseCodeBlock } from "@/components/cruise/code-block";

// Used in a Server Component layout: the case next/link's Link can't handle.
const LAYOUT = `// app/dashboard/layout.tsx (a Server Component)
import { CruiseDashboardLayout } from "@/components/cruise/blocks/dashboard-layout";
import { CruiseNextLink } from "@/components/cruise/next-link";

export default function DashboardLayout({ children }: { children: React.ReactNode }) {
  return (
    <CruiseDashboardLayout
      brand="Kiosk"
      logoHref="/dashboard"
      linkComponent={CruiseNextLink}
      nav={[
        { label: "Overview", href: "/dashboard" },
        { label: "Orders", href: "/dashboard/orders" },
      ]}
    >
      {children}
    </CruiseDashboardLayout>
  );
}`;

export default function NextLinkExample() {
  return (
    <div className="flex flex-col gap-4">
      <p className="max-w-(--measure)">
        Pass it as <code>linkComponent</code> and the block&apos;s links navigate client-side, with no full page reload.
        Passing next/link&apos;s <code>Link</code> itself from a Server Component fails; this wrapper works there and in
        client components.
      </p>
      <CruiseCodeBlock code={LAYOUT} language="tsx" />
    </div>
  );
}
```

## HTML

Needs theme.css (https://cruiseui.dev/theme.css).

```html
<!-- Plain HTML has no client-side router: a normal link does the same job -->
<a href="/dashboard">Dashboard</a>
```

## Props: CruiseNextLink

No props.

## Accessibility

- Renders a real <a> with an href, like next/link.
