Route tree types #824
-
is there a way to get a type of all the possible routes import { z } from 'zod'
import { Route, useRouter } from "@tanstack/react-router";
import { authlayout } from "./AuthLayout";
import { SignInForm } from "./components/SignInForm";
import { router } from '@/main';
const signinRouteSearchParamsSchema = z.object({
redirect: z.string().optional(),
email: z.string().email().optional(),
});
export const signinRoute = new Route({
getParentRoute: () => authlayout,
path: "/",
validateSearch: (search) => {
return signinRouteSearchParamsSchema.parse(search);
},
component: ({}) => {
const router = useRouter();
return (
<div className="w-full h-full flex items-center justify-center">
<SignInForm />
</div>
);
},
}); in my case am trying to make sure you can only pass valid routes to redirect: z.string().optional(), instead of just a string |
Beta Was this translation helpful? Give feedback.
Answered by
schiller-manuel
Dec 10, 2023
Replies: 2 comments 20 replies
-
How would a type of all possible routes help? Wouldn't you need that information at runtime? |
Beta Was this translation helpful? Give feedback.
16 replies
-
i used to use this and works fine import {ParseRoute} from "@tanstack/react-router";`
`export type TRoutes = ParseRoute<typeof routeTree>["fullPath"]; but now i keep getting error of Module '"@tanstack/react-router"' has no exported member 'ParseRoute'.ts(2305) |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How about something like this: