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
Top comments (0)