useRouteLoaderData

useRouteLoaderData

返回指定路由的 ID 对应的加载器数据。

¥Returns the loader data for a given route by ID.

import { useRouteLoaderData } from "@remix-run/react";

function SomeComponent() {
  const { user } = useRouteLoaderData("root");
}

Remix 会自动创建路由 ID。它们只是路由文件相对于应用文件夹的路径,不带扩展名。

¥Remix creates the route IDs automatically. They are simply the path of the route file relative to the app folder without the extension.

路由文件名 路由 ID
app/root.tsx "root"
app/routes/teams.tsx "routes/teams"
app/routes/teams.$id.tsx "routes/teams.$id"
Remix v2.17 中文网 - 粤ICP备13048890号