Skip to main content

useFormAction

Resolves the URL to the closest route in the component hierarchy instead of the current URL of the app. This is used internally by <Form> to resolve the action to the closest route.

Parameters

string
The action to append to the closest route URL. Defaults to the closest route URL if not provided.
object
"route" | "path"
default:"\"route\""
The relative routing type to use when resolving the action:
  • "route" (default) - Relative to the route hierarchy
  • "path" - Relative to the URL path segments

Return Value

string
The resolved action URL string.

Type Declaration

Usage Examples

Basic Form Action

Custom Action Path

Multiple Actions on Same Route

Relative Routing

Common Patterns

Dynamic Form Actions

Form with Index Route

Preserving Search Params

Nested Routes

Notes

  • Available in Framework and Data modes only
  • When action is not provided, it defaults to the current route URL
  • Automatically handles basename if configured in your router
  • Search params from the current location are preserved when action is null or .
  • Index routes automatically append ?index to the action URL
  • The relative option affects how .. paths are resolved

How It Works

The hook resolves the action URL based on:
  1. The route hierarchy (when relative: "route")
  2. The URL path segments (when relative: "path")
  3. The current basename configuration
  4. Whether the route is an index route