How to handle re-submitted form changes after user go back in browser history? #875
-
| Hello, first of all, thanks for Inertiajs it's so awesome, you guys doing a great job! In my Inertia/Vue3/Laravle app I have a form on a route, lets say /meetings/create. After I fill in the inputs I press submit and I got redirected to /meetings/1. Now if I go back in the browser (cause I maybe want to change my inputs) and press again submit another db entity got created and I got redirected to /meetings/2. How can I avoid this behavior? My first idea was to somehow manipulate the browser history and redirect the user to /meetings/1/edit, when he gos back in the browser history... Whats the best practice here, or how you guys handle such issues? Thank you! | 
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
| Bump... | 
Beta Was this translation helpful? Give feedback.
-
| would be very great to get some help on this issue! | 
Beta Was this translation helpful? Give feedback.
-
| Without seeing your actual code its difficult to answer... In my opinion you should avoid manipulating the browser history. In general, you should reset the form after submit, something like: import { useForm } from '@inertiajs/inertia-vue3'
setup () {
  const form = useForm({
    email: '',
  })
  const submit = () => {
    form.post('/meetings', {
      onFinish: () => form.reset(),
    })
  }
  return { form, submit }
} | 
Beta Was this translation helpful? Give feedback.
-
| Oh I see your point @Sairahcaz, if it feels intuitive then I don't think its broken at all. You can manipulate the browser history using  I also recommend reading the full Inertia docs, not very long but very helpful, e.g. Remembering state and Replace link. | 
Beta Was this translation helpful? Give feedback.
Oh I see your point @Sairahcaz, if it feels intuitive then I don't think its broken at all.
You can manipulate the browser history using
window.history.replaceState, see replaceState() Mozilla docs.I also recommend reading the full Inertia docs, not very long but very helpful, e.g. Remembering state and Replace link.