<form> that submits data to actions via fetch, activating pending states in useNavigation which enables advanced user interfaces beyond a basic HTML form.
Type Declaration
Props
string
The URL to submit the form data to. If
undefined, this defaults to the closest route in context.HTMLFormMethod
The HTTP verb to use when the form is submitted. Supports
"get", "post", "put", "patch", and "delete".Native forms only support "get" and "post", so avoid the other verbs if you’d like to support progressive enhancement.'application/x-www-form-urlencoded' | 'multipart/form-data' | 'text/plain'
The encoding type to use for the form submission.
boolean
Replaces the current entry in the browser History stack when the form navigates. Use this if you don’t want the user to be able to click “back” to the page with the form on it.
any
State object to add to the History stack entry for this navigation.
boolean
Prevent the scroll position from resetting to the top of the viewport on completion of the navigation when using the
<ScrollRestoration> component.RelativeRoutingType
Determines whether the form action is relative to the route hierarchy or the pathname.
boolean
Forces a full document navigation instead of client side routing and data fetch.
When
false, skips the navigation and submits via a fetcher internally. This is essentially a shorthand for useFetcher + <fetcher.Form> where you don’t care about the resulting data.string
Indicates a specific fetcherKey to use when using
navigate={false} so you can pick up the fetcher’s state in a different component using useFetcher.boolean
Enables a View Transition for this navigation. To apply specific styles during the transition, see
useViewTransitionState.DiscoverBehavior
Defines the form lazy route discovery behavior.
- render (default) - Discover the route when the form renders
- none - Don’t eagerly discover, only discover if the form is submitted
Examples
Basic Form
With Pending UI
File Upload
Search Form (GET)
Without Navigation (Fetcher)
Progressive Enhancement
Behavior
- After a form’s action completes, all data on the page is automatically revalidated to keep the UI in sync with the data
- Server rendered pages are interactive at a basic level before JavaScript loads
- After JavaScript loads, React Router takes over enabling web application user experiences
- Form submissions can be cancelled by the user or interrupted by other navigations
- Multiple forms can be submitted simultaneously and React Router will track them all
Notes
- Use
<Form>for submissions that should change the URL or add an entry to the browser history stack - Use
<fetcher.Form>ornavigate={false}for forms that shouldn’t manipulate the browser History stack - All standard HTML form attributes are supported
- Progressive enhancement allows forms to work before JavaScript loads