V
V
Vladimir2020-02-24 06:38:52
React
Vladimir, 2020-02-24 06:38:52

How to implement a ban on switching to a route without authorization?

Good morning. Please tell me how it is possible using React Routing to prevent the transition to /register is acceptable if the server did not respond true. Suppose a person has entered the site and he is not authorized, he does not need to show the page for authorized users, only after authorization do he decide whether to let him in or not. Thank you.

UPD: Here is a very interesting implementation, in progress ..

Tyk

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Robur, 2020-02-24
@Robur

just render the route or not depending on whether the user is logged in

{isAuthoruzed && <Route path='profile'><Profile/></Route>}

you can wrap it in ProtectedRoute, there is an example in the documentation, reading it is faster than writing a question on a toaster

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question