N
N
newUser20212021-04-24 16:07:39
React
newUser2021, 2021-04-24 16:07:39

React Router and .goBack(): How to undo a site visit?

Good afternoon. The site has a back
button that, when clicked, takes the user to the previous page. Implemented using react-router : The problem is that if the user came to the site from another site, for example from google.com -> mysite.com . Then by clicking on the back button it will go to google.com And you need to make it so that if by clicking on the back the user can get (leave the site), then in this case, either hide the button or redirect the user to the main page of the site. Can you please tell me how can I do this with react-router?

history.goBack();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Valery, 2021-05-01
@vmakhnyuk

There is a ready-made solution
. And if you don’t like it, I would suggest sending in each route of your application

state: { 
      from: location.pathname
  }

If fromnothing, then do not draw the button

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question