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 it with npx shadcn@latest add @cruiseui/cruise-next-link.
Install
Terminal
npx shadcn@latest add @cruiseui/cruise-next-linkFirst time? Installation shows the one-off components.json setup (the @cruiseui registry) and how to turn the theme on.
Example
Pass it as linkComponent and the block's links navigate client-side, with no full page reload. Passing next/link's Link itself from a Server Component fails; this wrapper works there and in client components.
// 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>
);
}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's links navigate client-side, with no full page reload.
Passing next/link'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>
);
}
<!-- Plain HTML has no client-side router: a normal link does the same job -->
<a href="/dashboard">Dashboard</a>Needs theme.css. Interactive parts (menus, tabs, drawers) also need the script in the spec for that component.
When to use it
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>).
Props
CruiseNextLink
No props.
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…).
Accessibility
- Renders a real <a> with an href, like next/link.