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.
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.
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.
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 false.
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.
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.