How to Use Shadcn UI with Next.js for Button Link

How to Use Shadcn UI with Next.js for Button Link

In this tutorial, we’ll see how to use button Link using Next.js and Shadcn UI.
how to use shadcn ui in next js 13

Before use Button with Link in next js 13 with shadcn ui you need to install npx shadcn-ui add button.

npx shadcn-ui@latest add button

Creating a Button as a Child Element with a Link in Next.js Using Shadcn UI.

import Link from next/link

import { Button } from @/components/ui/button

export default function page() {
return (
<div>
<Button asChild>
<Link href=“/login”>Login</Link>
</Button>
</div>
)
}


2.Creating a Button Link in Next.js with Shadcn UI, Featuring Variants like Secondary, Destructive, and Outline.

import Link from next/link

import { Button } from @/components/ui/button

export default function page() {
return (
<div className=“space-x-6”>
<Button asChild>
<Link href=“/login”>Login</Link>
</Button>
<Button asChild variant=“secondary”>
<Link href=“/login”>Login</Link>
</Button>
<Button asChild variant=“destructive”>
<Link href=“/login”>Login</Link>
</Button>
<Button asChild variant=“outline”>
<Link href=“/login”>Login</Link>
</Button>
</div>
)
}

3.You can use the buttonVariants helper to create a link that looks like a button.

import Link from next/link;

import { buttonVariants } from @/components/ui/button;

export default function page() {
return (
<div>
<Link className={buttonVariants({ variant: outline })} href=“/login”>
login
</Link>
</div>
);
}

See Also

👉Building a Next.js Hover-Activated Dropdown Menu with Shadcn UI
👉Next.js with Shadcn UI Product Cards Example
👉how to use icon in shadcn ui with next js 13
👉create responsive navbar in next 13 with shadcn ui
👉create footer section in next 13 with shadcn ui
👉Next.js Image File Upload and Preview with Shadcn UI
👉create sidebar in next 13 with shadcn ui
👉how to use skeleton loading next 13 with shadcn ui
👉next 13 with shadcn ui date picker example
👉next 13 with shadcn ui pagination example

Leave a Reply

Your email address will not be published. Required fields are marked *