一键导入
tanstack-router
TanStack Router patterns for routing, navigation, search params, and layouts. Use when creating routes, navigating, or working with URL state.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
TanStack Router patterns for routing, navigation, search params, and layouts. Use when creating routes, navigating, or working with URL state.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Code review of current PR/commit changes against project coding standards. Use when the user asks for a code review or mentions reviewing changes.
Reference for the Tangle component YAML specification format
Guidelines for building well-structured, maintainable ML pipelines in Tangle
Analyzes merged PRs from the past week, identifies user-facing changes, and opens a draft PR to the TangleML/website docs repo with updated documentation. Use when running the weekly documentation sync, or when the user invokes /docs-update.
React and React Compiler patterns for this project. Use when writing React components, hooks, providers, or working with React Compiler compatibility.
Run validation and testing commands for the project. Use when the user asks to validate, lint, typecheck, or run tests.
| name | tanstack-router |
| description | TanStack Router patterns for routing, navigation, search params, and layouts. Use when creating routes, navigating, or working with URL state. |
This project uses code-based routing (not file-based) with TanStack Router v1.
All routes are defined in src/routes/router.ts using createRoute and assembled into a tree with addChildren:
const mainLayout = createRoute({
id: "main-layout",
getParentRoute: () => rootRoute,
component: RootLayout,
});
const indexRoute = createRoute({
getParentRoute: () => mainLayout,
path: APP_ROUTES.HOME,
component: Editor,
});
// Assemble tree
const appRouteTree = mainLayout.addChildren([
indexRoute,
quickStartRoute,
settingsRouteTree,
editorRoute,
]);
Use the APP_ROUTES constant object for all route paths — never hardcode path strings:
export const APP_ROUTES = {
HOME: "/",
QUICK_START: "/quick-start",
PIPELINE_EDITOR: `${EDITOR_PATH}/$name`,
RUN_DETAIL: `${RUNS_BASE_PATH}/$id`,
RUNS: RUNS_BASE_PATH,
SETTINGS: "/settings",
} as const;
useNavigate hook:
const navigate = useNavigate();
navigate({ to: `${APP_ROUTES.RUNS}/${runId}` });
Handle Ctrl/Cmd+Click for new tabs:
const handleRowClick = (e: MouseEvent<HTMLElement>) => {
if (e.ctrlKey || e.metaKey) {
window.open(clickThroughUrl, "_blank");
return;
}
navigate({ to: clickThroughUrl });
};
Link component with active state:
import { Link } from "@tanstack/react-router";
<Link
to={item.to}
replace
activeProps={{ className: "is-active" }}
>
{({ isActive }) => (
<Button variant="ghost" className={cn("w-full", isActive && "bg-accent")}>
<Icon name={item.icon} size="sm" />
<Text size="sm">{item.label}</Text>
</Button>
)}
</Link>
This project uses TanStack Query for data fetching, not route loaders. Routes do not define loader functions — use query hooks in components instead.
beforeLoad is only used for redirects and simple param extraction:
const settingsIndexRoute = createRoute({
getParentRoute: () => settingsLayoutRoute,
path: "/",
beforeLoad: () => {
throw redirect({ to: APP_ROUTES.SETTINGS_BACKEND });
},
});
Use useSearch with type casting and manual validation (not Zod):
type RunSectionSearch = { page_token?: string; filter?: string };
const search = useSearch({ strict: false }) as RunSectionSearch;
const filters = parseFilterParam(search.filter);
For complex search param management, see the useRunSearchParams hook in src/hooks/useRunSearchParams.ts which provides setFilter, clearFilters, hasActiveFilters, etc.
Validate search params with type guards, not Zod:
function isValidAnnotationFilter(value: unknown): value is AnnotationFilter {
return (
isRecord(value) &&
typeof value.key === "string" &&
(value.value === undefined || typeof value.value === "string")
);
}
const { id, subgraphExecutionId } = useParams();
| Hook | Use Case |
|---|---|
useNavigate() | Programmatic navigation |
useParams() | Route parameters ($id, $name) |
useSearch({ strict: false }) | Search/query params |
useLocation() | Current pathname |
useRouter() | Router instance (history, back navigation) |
useRouterState() | Advanced state (resolved location, pending state) |
Layouts use <Outlet /> for child routes. The root layout (RootLayout) wraps providers:
rootRoute
├── mainLayout (RootLayout: BackendProvider > ComponentSpecProvider > AppMenu + Outlet)
│ ├── indexRoute
│ ├── settingsLayoutRoute (SettingsLayout: sidebar + Outlet)
│ │ ├── settingsBackendRoute
│ │ └── secretsRouteTree
│ ├── editorRoute
│ └── runDetailRoute
└── Auth callback routes (no layout)
export const router = createRouter({
routeTree: rootRouteTree,
defaultPreload: "intent",
scrollRestoration: true,
history,
basepath: IS_GITHUB_PAGES ? "" : basepath,
});
defaultPreload: "intent" — preloads routes on hover/focusscrollRestoration: true — restores scroll position on back navigation