useParams返回一个键值对对象,其中包含当前 URL 中由路由匹配的动态参数。子路由继承其父路由的所有参数。
import { useParams } from "@remix-run/react";
function SomeComponent() {
const params = useParams();
// ...
}
假设 routes/posts/$postId.tsx 这样的路由被 /posts/123 匹配,则 params.postId 将为 "123"。 通配符路由的参数可作为 params["*"] 使用。