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
You may use themethod option to set the request’s HTTP method to get, post, put, patch, delete, or query. 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.
QUERY Method
v3.10.0+ Laravel Adapter v3.6.0+ Sometimes you may wish to send search filters that are too large or too deeply nested for a query string. LikeGET, the QUERY HTTP method is safe and idempotent, but it sends its data in the request body instead of the URL. You may make a QUERY visit using the router.query() method.
GET visits, QUERY visits preserve component state by default. The data isn’t part of the URL, so refreshing the page or sharing its link loses the filters. GET remains the better choice for filters that users should be able to bookmark or share.
Inertia remembers the request body of a page rendered by a QUERY visit and resends it on reloads, partial reloads, polling, deferred props, and infinite scroll requests, so these keep returning the filtered results. Any data passed to router.reload() is merged into the remembered body.
Wayfinder
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 method option will take precedence.
Data
You may use thedata option to add data to the request.
get(), post(), put(), patch(), and query() 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 methods to make client-side visits. These methods are 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 may pass a function to the props option. This function receives the current props (including any once props) and should return the new props.
errorBag option allows you to specify which error bag to use when handling validation errors in the onError callback.
Make sure that any route you push on the client side is also defined on the server side. If the user refreshes the page, the server will need to know how to render the page.
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, query, 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 may cancel all in-flight visits using therouter.cancelAll() method. By default, this cancels all synchronous, asynchronous, and prefetch requests.
Cancel Tokens
For more granular control, you may cancel individual visits using a cancel token. Inertia automatically generates a cancel token and provides it via theonCancelToken() callback prior to making the visit.
onCancel() and onFinish() event callbacks will be executed when a visit is canceled.
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 canceled. Returning false from onHttpException() or onNetworkError() will prevent the corresponding global event from being fired and its default behavior.
onSuccess() and onError() callbacks. When doing so, the “finish” event will be delayed until the promise has resolved.