Docs
React 路由

React 路由

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

创建项目

¥Create project

pnpm create react-router@latest my-app

运行 CLI

¥Run the CLI

运行 shadcn init 命令来设置你的项目:

¥Run the shadcn init command to setup your project:

pnpm dlx shadcn@latest init

添加组件

¥Add Components

你现在可以开始向你的项目添加组件。

¥You can now start adding components to your project.

pnpm dlx shadcn@latest add button

上面的命令将把 Button 组件添加到你的项目中。然后你可以像这样导入它:

¥The command above will add the Button component to your project. You can then import it like this:

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 flex-col items-center justify-center min-h-svh">
      <Button>Click me</Button>
    </div>
  )
}