So what I want to do here is tap into a Hook that I will create which has a state variable named toHome and a related set/update method called setToHome(). In my contrived example, I know that I want to at the very least redirect to Home once the user clicks on "CLEAR TODOS", in a better example I would notify the user (which I am not doing in this code) and then redirect to Home because our todo list is cleared. If we look at the Todos.js file, we will see that we have a function that calls dispatch() and sends CLEAR_TODOS as an action type to our reducer. You can click on users name, that will take you to view that users profile. Here is a solution: In our app, lets say users list is public. Redirecting user to their previous/intended page. Without thinking of all of the edge cases for this feature, I just want to get a basic redirect working using some basic logic, a quick and dirty example and we can iron the details out later if we want to. Because here i will show you how to can redirect user to their previous/intended page after login in react app using react router. I have contrived a very simple feature that will redirect the user to the Home route once the Todos are cleared. One of the routes loads a Todo component in which I employ the useReducer hook in order to keep track of the todos state (local state). To set the stage, I have an application with routing and pages already set up. A lot of these short blog posts are just for me to find later when I forget how to do something, but I thought this little trick that you can do with React router was worth sharing.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |