110k

React Router

为 React Router 安装和配置 shadcn/ui。

创建项目

pnpm dlx shadcn@latest init -t react-router

对于 monorepo 项目,使用 --monorepo 参数:

pnpm dlx shadcn@latest init -t react-router --monorepo

添加组件

现在您可以开始将组件添加到项目中。

pnpm dlx shadcn@latest add button

上述命令会将 Button 组件添加到您的项目中。然后,您可以这样导入它:

app/routes/home.tsx
import { Button } from "@/components/ui/button"
 
import type { Route } from "./+types/home"
 
export function meta({}: Route.MetaArgs) {
  return [
    { title: "New React Router App" },
    { name: "description", content: "Welcome to React Router!" },
  ]
}
 
export default function Home() {
  return (
    <div className="flex min-h-svh flex-col items-center justify-center">
      <Button>点击我</Button>
    </div>
  )
}