0

There is stepper of pages with steps 1 2 3. If a page reloads on the second or third step, it has to redirect to the first step.

How can I detect that page has been reloaded?

  • Possible duplicate of [Check if page gets reloaded or refreshed in Javascript](https://stackoverflow.com/questions/5004978/check-if-page-gets-reloaded-or-refreshed-in-javascript) – Fakebounce Jun 03 '19 at 09:54
  • where are you storing your page number variable? If it is memory then it would always get reinitialised at the page reload. – Naman Kheterpal Jun 03 '19 at 09:55
  • At the moment page number variables are not storing. Only redirect to the next page is using –  Jun 03 '19 at 11:21

1 Answers1

1

You can catch page load when componentDidMount of your root component is fired :

class App extends React.Component {
  constructor(props) {
    super(props);
  }

  componentDidMount() {
    // do something
  }

}
  • How can I detect in componentDidMount that page has been reloaded? –  Jun 03 '19 at 11:22
  • just put the code you want to execute when the page is reloaded in componentDidMount and react will run this function everytime the app is realoaded – Abderrahim Soubai-Elidrisi Jun 03 '19 at 11:24
  • The problem is how to detect that page is reloaded –  Jun 03 '19 at 11:31
  • 1
    Pass a prop from page 1 to page 2 to page 3, etc. If that prop is present, the page wasn't reloaded. If it is it's missing, that means the page was reloaded, and redirect the user – Cody Swann Jun 04 '19 at 09:17