React Router v7 已發布。 查看文件
useFormAction

useFormAction

解析 URL 為元件階層中最接近的路由,而不是應用程式的目前 URL。

這在內部由 <Form> 使用,將動作解析為最接近的路由,但也可以作為一般用途使用。

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

function SomeComponent() {
  // closest route URL
  const action = useFormAction();

  // closest route URL + "destroy"
  const destroyAction = useFormAction("destroy");
}

簽名

useFormAction(action, options)

action

選用。要附加到最接近的路由 URL 的動作。

options

唯一的選項是 { relative: "route" | "path"}

  • route 預設 - 相對於路由階層,而不是 URL
  • path - 使動作相對於 URL 路徑,因此 .. 將刪除一個 URL 區段。
文件和範例根據 MIT