router.visit() method.
router.visit().
reload() method is a convenient, shorthand method that automatically visits the current page with preserveState and preserveScroll both set to true, making it the perfect method to invoke when you just want to reload the current page’s data.
Method
When making manual visits, you may use themethod option to set the request’s HTTP method to get, post, put, patch or delete. The default method is get.
put or patch is not supported in Laravel. Instead, make the request via post, including a _method field set to put or patch. This is called form method spoofing.
Wayfinder
v2.1.2+ When using Wayfinder, you can pass the resulting object directly to any router method. The router will infer the HTTP method and URL from the Wayfinder object.method option, the methodoption will take precedence.
Data
You may use thedata option to add data to the request.
get(), post(), put(), and patch()methods all accept data as their second argument.
Custom Headers
Theheaders option allows you to add custom headers to a request.
Global Visit Options
You may configure avisitOptions callback when initializing your Inertia app to modify visit options globally for every request. The callback receives the target URL and the current visit options, and should return an object with any options you want to override.
File Uploads
When making visits / requests that include files, Inertia will automatically convert the request data into aFormData object. If you would like the request to always use a FormData object, you may use the forceFormData option.
Browser History
When making visits, Inertia automatically adds a new entry into the browser history. However, it’s also possible to replace the current history entry by setting thereplace option to true.
replace to true.
Client Side Visits
You can use therouter.push and router.replace method to make client-side visits. This method is useful when you want to update the browser’s history without making a server request.
errorBag) will be merged with the current page. This means you are responsible for overriding the current page’s URL, component, and props.
If you need access to the current page’s props, you can pass a function to the props option. This function will receive the current page’s props as an argument and should return the new props.
The errorBag option allows you to specify which error bag to use when handling validation errors in the onError callback.
Prop Helpers
Inertia provides three helper methods for updating page props without making server requests. These methods are shortcuts torouter.replace() and automatically set preserveScroll and preserveState to true.
State Preservation
By default, page visits to the same page create a fresh page component instance. This causes any local state, such as form inputs, scroll positions, and focus states to be lost. However, in some situations, it’s necessary to preserve the page component state. For example, when submitting a form, you need to preserve your form data in the event that form validation fails on the server. For this reason, thepost, put, patch, delete, and reload methods all set the preserveState option to true by default.
You can instruct Inertia to preserve the component’s state when using the get method by setting the preserveState option to true.
preserveState option to “errors”.
preserveState option based on the response by providing a callback.
Scroll Preservation
When navigating between pages, Inertia mimics default browser behavior by automatically resetting the scroll position of the document body (as well as any scroll regions you’ve defined) back to the top of the page. You can disable this behavior by setting thepreserveScroll option to true.
preserveScroll option to “errors”.
preserveScroll option based on the response by providing a callback.
Partial Reloads
Theonly option allows you to request a subset of the props (data) from the server on subsequent visits to the same page, thus making your application more efficient since it does not need to retrieve data that the page is not interested in refreshing.
View Transitions
You may enable View transitions for a visit by setting theviewTransition option to true. This will use the browser’s View Transitions API to animate the page transition.
Visit Cancellation
You can cancel a visit using a cancel token, which Inertia automatically generates and provides via theonCancelToken() callback prior to making the visit.
onCancel() and onFinish() event callbacks will be executed when a visit is cancelled.
Event Callbacks
In addition to Inertia’s global events, Inertia also provides a number of per-visit event callbacks.false from the onBefore() callback will cause the visit to be cancelled.
onSuccess() and onError() callbacks. When doing so, the “finish” event will be delayed until the promise has resolved.