Can't find replace attribute on <Navigate />
This is basically my code, I am trying to check if the user is authenticated, if not then redirect to login page.
However, the problem is, I can't set replace attribute to <Navigate /> component. is there any other way to achieve same thing with or without <Navigate />
13 Replies
useNavigate
Basically use the returned navigate
function even before you start rendering and set replace: true
in the options
argument.
yep this works
i'd suggest returning
<>{props.children}</>
as accessing children outside of jsx can cause issuesI've refactored code to this:
should i still wrap props.children to empty jsx tags?
Yeah
Just to be safe
Ok, it works but I had no issues without it
Thanks for tip
Yea it's entirely possible that it's fine without it, but if by chance
children
changed then that wouldn't be reflectedI have one more question, you may know
Is this the correct way to resolve children, so it should proceed only when loading state has been set to false
I'm not sure if this will cause issues as well
Doing the isLoading check inside children() is just doing double work, I'm not sure if it's actually bad but it's defs not necessary
I've tried without it, and it didn't show children
That's good right?
this should be fine
Oh yeah, that totally works haha
Thank you very much
I've noticed that
and
do the same thing
checks out