React Routing Question.
hey yall! im currently working on a side project with a react frontend and typescript/node backend. here is the router configuration:
my questions is:
- say an authenticated user visits
/client/create
which renders the CreateJot
component.
- now, lets assume the user refreshes his/her's page.
- now, on refresh the page does not redirect back the page the user was in and redirects to /client/discover
. (this is most likely due to the navigate('/client/discover')
call i have in the AuthProivder
component.
how do i redirect the user based on the page he/she was in? for now, i can only think of storing the current page state in localStorage and updating it each time and using that for redirection.4 Replies
my
AuthProvider
code:
To clarify, is this the process?:
- Authenticated user visits
/client/create
- They refresh their page while on that page
What do you want to happen in that case? Typically if the user is authenticated and they're on the 'login' page (which seems like what you have essentially with the /client/create
here), they would be automatically redirected to some page, like the home page or something.
Is that what you want to happen, or do you want to redirect the user to whatever page they happened to be on before they navigated to /client/create
?never mind, i figured it out. what i wanted was when the user refreshes the page, i wanted the user to be redirected to the same page the user was in (the page from where the refresh happened). with my logic above it always redirected to
/client/discover
. I removed that line.Ah no worries, glad you figured it out.