-
Notifications
You must be signed in to change notification settings - Fork 24
Open
Description
Hey there!
I propose to add Navigate component from react-router-dom to makeRoute, something like this:
export default function AuthenticationLayout() {
if (!authenticated)
return <LoginRoute.Navigate />;
return <HomeRoute.Navigate />;
}I made this changes for my own:
export type RouteBuilder<
Params extends z.ZodSchema,
Search extends z.ZodSchema
> = {
Navigate: React.FC<
Omit<NavigateProps, "to"> & z.input<Params> & { search?: z.input<Search> }
>;
};
routeBuilder.Navigate = function RouteLink({
search: linkSearch,
...props
}: Omit<NavigateProps, "to"> & z.input<Params> & { search?: z.input<Search> }) {
const params = info.params.parse(props);
const extraProps = { ...props };
for (const key of Object.keys(params)) {
delete extraProps[key];
}
return (
<Navigate
{...props}
to={routeBuilder(info.params.parse(props), linkSearch)}
/>
);
};This would work great for this cases. Works for me.
What do you think?
hgd
Metadata
Metadata
Assignees
Labels
No labels