How to use React Router’s redirect function?

Posted by Jennifer | Updated on

Want to use React Router’s redirect function? There’s a good example of how to use the onEnter hook in the auth-flow example.

Here is an example code:

As you can see, when the /dashboard route is accessed the requireAuth function is called. It receives two arguments: nextState, which is a RouterState object that represents the state the user is about to enter, and replaceState, a RedirectFunction that can be called to replace that state with something else.

If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@] Your question and answer will appear on and help other developers.

Related Questions & Answers