J
J
jslby2019-05-15 02:33:01
React
jslby, 2019-05-15 02:33:01

How to disable navigation to previous pages in React?

Hello. There is a router in which a person fills out his profile.
Looks like this:

/
/main-info
/job-info
/personal-info
/contact-info

I need to make it so that when the user enters the site, he is automatically redirected to the last page where he stopped, i.e.:
If the user from the main page went to / main-info and closed the site, then when he returns he should to get to /main-info again - this is not difficult to implement, you can store the route in localstorage, but here is one more condition:
If the user wants to go to the main one again, he will be redirected to /main-info
If he goes from /main-info to / job-info - then under no circumstances will it be able to get either to the main or to /main-info
It should simply be redirected
Naturally, protection from Incognito and changing the browser / computer will not help, but I really need an implementation without these exceptions, i.e. the user sits in the same browser and without Incognito

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Spirin, 2019-05-15
@jslby

if (storagePath && location.pathname !== storagePath) {
  return <Redirect to={storagePath} />;
}

return (
  <Switch>
    // routes
  </Switch>
);

Before moving to the next page of the questionnaire, you need to update the storagePath, and delete it when the filling is completed.

R
Robur, 2019-05-15
@Robur

Set up a redirect that will check what step the user was on last time and send it there.
It can be put either on each page or one global one that is rendered higher in the tree than all these pages.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question