Z
Z
zWaterFall2019-11-22 17:49:01
JavaScript
zWaterFall, 2019-11-22 17:49:01

How to prevent leaving the site due to history.goBack()?

In my React app I use react-router-dom for navigation.
The task was to redirect the user to the authorization form /user_registration or /user_login if he enters /special unregistered .
During execution, the following bug occurred: If you enter the application directly on /user_login, then after authorization it is thrown out of the site, since it fulfills history.goBack()
Now the question is: Is it possible to somehow prevent such an exit from the application?
For example, if there is no previous visit to the site domain in the history, throw "/" on the main page.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman, 2019-11-22
@zWaterFall

I would check history.length and call history.goBack() if there is room to go back.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question