useParams

useParams

返回当前 URL 中与路由匹配的动态参数的键值对对象。子路由会从其父路由继承所有参数。

¥Returns an object of key/value pairs of the dynamic params from the current URL that were matched by the routes. Child routes inherit all params from their parent routes.

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

function SomeComponent() {
  const params = useParams();
  // ...
}

假设像 routes/posts/$postId.tsx 这样的路由与 /posts/123 匹配,那么 params.postId 将会是 "123"splat 路由 的参数可用作 params["*"]

¥Assuming a route like routes/posts/$postId.tsx is matched by /posts/123 then params.postId will be "123". Params for splat routes are available as params["*"].

Remix v2.17 中文网 - 粤ICP备13048890号