Docs
TanStack 路由

TanStack 路由

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

创建项目

¥Create project

首先创建一个新的 TanStack Router 项目:

¥Start by creating a new TanStack Router project:

pnpm create tsrouter-app@latest my-app --template file-router --tailwind --add-ons shadcn

添加组件

¥Add Components

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

¥You can now start adding components to your project.

pnpm dlx shadcn@canary add button

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

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

src/routes/index.tsx
import { createFileRoute } from "@tanstack/react-router"
 
import { Button } from "@/components/ui/button"
 
export const Route = createFileRoute("/")({
  component: App,
})
 
function App() {
  return (
    <div>
      <Button>Click me</Button>
    </div>
  )
}