搜索

PythonReactSEOPDF
GitHub Skill

create-route

Create React Router 7 routes with proper type imports, loaders, and actions. Use when adding new pages, API endpoints, layouts, or route files.

tech-with-seth☆ 1 仓库 Stars0 仓库 Forks

安装与使用

请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。

查看来源 ↗使用指南

技能说明

Create Route

When to Use

  • Creating new pages or views
  • Adding API endpoints
  • Creating layout routes with <Outlet />

Critical Rules

1. Route Type Imports
// ALWAYS use this pattern:
import type { Route } from './+types/my-route';

// NEVER use relative paths:
// import type { Route } from '../+types/my-route';  // WRONG!

If types are missing: Run npm run typecheck - NEVER change the import path.

2. Destructure Directly
// CORRECT
export async function action({ request, params }: Route.ActionArgs) {}

// WRONG
export async function action(args: Route.ActionArgs) {
    const { request } = args;  // Don't do this!
}
3. Access Data via Props
// CORRECT
export default function MyPage({ loaderData }: Route.ComponentProps) {}

// WRONG
const data = useLoaderData();  // Don't use hooks!

Quick Start

import type { Route } from './+types/my-page';
import { data, redirect } from 'react-router';

export async function loader({ request }: Route.LoaderArgs) {
    const user = await requireUser(request);
    return { user };
}

export async function action({ request }: Route.ActionArgs) {
    const formData = await request.formData();
    // Handle POST/PUT/DELETE
    return redirect('/success');
}

export default function MyPage({ loaderData }: Route.ComponentProps) {
    return (
        <>
            <title>Page Title | Iridium</title>
            <meta name="description" content="Description" />
            {/* Content */}
        </>
    );
}

Checklist

  1. Create route file in app/routes/
  2. Register in app/routes.ts
  3. Run npm run typecheck to generate types
  4. Add path to Paths constant if reusable

Templates

Full Reference

See .github/instructions/react-router.instructions.md for:

  • Nested routes & layouts
  • Dynamic segments & optional segments
  • Streaming with Suspense
  • Error boundaries
  • Navigation patterns

使用示例

查看来源仓库中的使用示例与配置说明。

查看来源 ↗

来源历史

收录时间
2026-01-20
索引更新时间
2026-01-26
Branch
main

收录与同步日期属于本站记录。源码修改历史请查看来源仓库。

GitHub ↗

chat Comments (0)

chat_bubble_outline

No comments yet. Be the first to share your thoughts!