TanStackT
TanStack3mo ago
6 replies
spotty-amber

Is it possible to access router.buildLocation() in a Server Route?

Did a cursory search for buildLocation, and no results returned...but is it possible to access buildLocation() (or something simillar) on a server route so that I can build a typesafe redirect url?

export const Route = createFileRoute("/(api)/api/auth/callback")({
    validateSearch: z.object({
        code: z.string().optional(),
        next: z.string().optional(),
    }),
    server: {
        handlers: {
            GET: async ({ request }) => {

                const url = XXX.buildLocation({ to: "/workspace/dashboard" })

                // do business logic

                return Response.redirect([PUT RESULT HERE], 302)
            },
        },
    },
})


I can't seem to find a helper function at the moment, am I missing something or do I need to hardcode urls for server routes for now? Thanks a lot!
Was this page helpful?