Aaron McCloud
08/04/2021, 11:59 PM<UnauthenticatedRoute>
's, but for them if I pass in a state
when I navigate to them with react-router-dom
's Link
, the state
is stripped out.
I know I need to change something here:
<Route {...rest}>
{!isAuthenticated ? (
children
) : (
<Redirect to={redirect === "" || redirect === null ? "/" : redirect} />
)}
</Route>
To pass the state
in <Link to={{ to="./classes/:id", state: { stuff: 'cool' }}}>
through. But, I haven't figured out how yet.
I'll be cranking on it later this evening, but any thoughts/help would be appreciated. 🙏Jay
Aaron McCloud
08/05/2021, 1:08 AMprops.location.state
Aaron McCloud
08/05/2021, 1:09 AMAaron McCloud
08/05/2021, 1:09 AMAaron McCloud
08/05/2021, 1:10 AMJay
Aaron McCloud
08/05/2021, 3:33 AMstate
is in the ...rest
, which is not passed down to children
Aaron McCloud
08/05/2021, 3:33 AMAaron McCloud
08/05/2021, 4:29 AMexport default function UnauthenticatedRoute(props) {
const { children, ...rest } = props;
const { isAuthenticated } = useAppContext();
const redirect = querystring("redirect");
return (
<Route {...rest}>
{
!isAuthenticated
? React.cloneElement(children, props)
: <Redirect to={redirect === "" || redirect === null ? "/" : redirect} />
}
</Route>
);
}
Aaron McCloud
08/05/2021, 4:30 AMReact.cloneElement(children, props)
, which is where the magic happens.Jay
Timothy Farland
08/08/2021, 10:53 PM