useFormAction

useFormAction

将 URL 解析为组件层次结构中最接近的路由,而不是应用的当前 URL。

¥Resolves the URL to the closest route in the component hierarchy instead of the current URL of the app.

<Form> 在内部使用它来将操作解析到最近的路由,但也可以通用。

¥This is used internally by <Form> to resolve the action to the closest route, but can be used generically as well.

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

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

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

签名

¥Signature

useFormAction(action, options)

action

可选。附加到最近路由 URL 的操作。

¥Optional. The action to append to the closest route URL.

options

唯一的选项是 { relative: "route" | "path"}

¥The only option is { relative: "route" | "path"}.

  • route default — 相对于路由层级,而非 URL

    ¥route default — relative to the route hierarchy, not the URL

  • path — 使操作相对于 URL 路径,因此 .. 将删除一个 URL 段。

    ¥path — makes the action relative to the URL paths, so .. will remove one URL segment.

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