When navigating browser history, Inertia restores pages using prop data cached in history state. However, Inertia does not restore local page component state since this is beyond its reach. This can lead to outdated pages in your browser history. For example, if a user partially completes a form, then navigates away, and then returns back, the form will be reset and their work will be lost. To mitigate this issue, you can tell Inertia which local component state to save in the browser history.Documentation Index
Fetch the complete documentation index at: https://inertiajs.com/docs/llms.txt
Use this file to discover all available pages before exploring further.
Saving Local State
To save local component state to the history state, use theuseRemember feature to tell Inertia which data it should remember.
form state changes, Inertia will automatically save this data to the history state and will also restore it on history navigation.
Multiple Components
If your page contains multiple components that use the remember functionality provided by Inertia, you need to provide a unique key for each component so that Inertia knows which data to restore to each component.Form Helper
If you’re using the Inertia form helper, you can pass a unique form key as the first argument when instantiating your form. This will cause the form data and errors to automatically be remembered.dontRemember() method. This is useful for sensitive fields like passwords that should not be stored in history state.
Manually Saving State
TheuseRemember hook watches for data changes and automatically saves those changes to the history state. Then, Inertia will restore the data on page load.
However, it’s also possible to manage this manually using the underlying remember() and restore() methods exposed by Inertia.