React Routing
How can I solve this
react-routing
problem .
So I have 3 pages /signup
, /login
and /todos
.
Now if a user is already sign in I want it to redirect to /todos
and if its a new user I want it to direct to /signup
. BUT I don't want the user to access /todos
without sign up like changing url to /todos
should give the default 404 .
One way is to remove the /todos
route and conditionally render the component but then how can I redirect user to /todos
when user successfully signup/login .
My question is how should I create a better routing system
https://pastecord.com/dogahesaqi.js4 Replies
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
you would probably use cookies instead of localStorage, unless you want user to be logged in forever. since you can set cookies to expire after given time (you'd probably set it for few days). and then, as bumble said, you would use global state that tells you whether there is cookie in the browser or not
you wouldn't use 404 error for that, instead you should just navigate him back to signup page.
so if user tried to navigate to
/todos
, you'd check if cookie is active. if it's not, navigate him back to signup page, else do nothing (keep him on /todos page)For todos I have three routes
/signup
, /login
and /todos
. I want to redirect conditionally if user is defined or not . I am using <Navigate>
but I am not sure if this is a good pattern or not . I will use Appwrite as BaaS and I will create session for it
https://pastecord.com/onoxuquxyz.jsUnknown User•2y ago
Message Not Public
Sign In & Join Server To View