Open bstivenprz opened 23 hours ago
Hey there!
I propose to add Navigate component from react-router-dom to makeRoute, something like this:
makeRoute
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
Is this just for the React-router?
This would probably be better as a PR.
Hey there!
I propose to add Navigate component from react-router-dom to
makeRoute
, something like this:I made this changes for my own:
This would work great for this cases. Works for me.
What do you think?
hgd