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
actionis 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
actionisnullor. - Index routes automatically append
?indexto the action URL - The
relativeoption affects how..paths are resolved
How It Works
The hook resolves the action URL based on:- The route hierarchy (when
relative: "route") - The URL path segments (when
relative: "path") - The current basename configuration
- Whether the route is an index route
Related
<Form>- Uses this hook internallyuseResolvedPath- Resolves paths relative to current locationuseHref- Resolves a full hrefuseSubmit- Programmatically submit forms