1

I have a multistep form, with user inputs in my second step. So, if the network crashes or for whatever reason user would need to reload this second step with the inputs, I want him to be able to do so, without being led to the default route. However, if the user wishes to navigate between steps typing in url, he shouldn't be able to do so.

This bit of code returns the user back home not only on manual taping, but also on reload:

useEffect(() => { 
  router.replace("?step=0");
}, []);

So, I have been thinking to check, if the current path basically stays same, no router.replace should happen. My code is definitely broken, but I assume thinking behind should be right:

useEffect(() => { 
  if(router.asPath !== router.asPath ) {router.replace("?step=0")};
}, []);

So basically the question is, how do I check if the path has changed, then do replace, if hasn't then just render same form step.

Katharina Schreiber
  • 1,187
  • 2
  • 11
  • 38

0 Answers0