跳到正文
语言22
菜单

文档 / 框架

React Router

把 UI Loft 项目添加到框架模式的 React Router 应用。新应用自带 Tailwind 和导入别名,所以只要三条命令。

版本
React
需要
Tailwind 4 + shadcn
设置时间
约 2 分钟

设置

  1. 创建应用

    如果已经有了就跳过。--yes 采用默认设置。

    终端
    npx create-react-router@latest my-app --yes
    cd my-app
  2. 设置 shadcn

    它会生成 components.json,说明新文件放在哪里。-d 采用默认设置。

    终端
    npx shadcn@latest init -d
  3. 添加一个项目

    从任意项目页面复制命令。文件会放进 app/components/。

    终端
    npx shadcn@latest add https://uiloft.dev/r/glow-button.json
  4. 使用它

    在路由中导入。

    app/routes/home.tsx
    import { GlowButton } from "~/components/glow-button"
    
    export default function Home() {
      return <GlowButton>Get started</GlowButton>
    }

须知

  • 导入路径以 ~/ 开头,而不是 @/。shadcn 会相应修改项目自身的导入。
  • 较旧或手动搭建的应用,需要先配好 Tailwind 4 和 ~/* 路径别名,再设置 shadcn。
  • 这些步骤已用 React Router 8 验证。

其他框架