T
TanStack7mo ago
fair-rose

Why aren't API routes available as a `to` typechecked destination in `Link`?

If I have an API route declare I seem unable to be able to do <Link to="/api/something" /> in a typesafe manner. The use case is using API routes for a Google Auth redirect.
19 Replies
fascinating-indigo
fascinating-indigo7mo ago
how would that look like? can you give more details?
fair-rose
fair-roseOP7mo ago
Since createFileRoute adds an entry to routeTree I'd assume it would work by having createAPIFileRoute also add an entry in routeTree.
fascinating-indigo
fascinating-indigo7mo ago
it does not i rather meant: why would you want to link to an API route?
fair-rose
fair-roseOP7mo ago
Google OAuth flow Well any OAuth flow really
fascinating-indigo
fascinating-indigo7mo ago
and thats kicked of by the API route?
fair-rose
fair-roseOP7mo ago
Yup. Basically /api/auth/google redirects to the Google OAuth flow
fascinating-indigo
fascinating-indigo7mo ago
so you need a hard reload still you cannot use client side navigation for that
fair-rose
fair-roseOP7mo ago
And then it comes back to /api/auth/google/callback which then should redirect to either /$lang/sign-in/error (in case of error) or /$lang/ (home) I cannot. Right.
fascinating-indigo
fascinating-indigo7mo ago
so you would need to set reloadDocument={true} on that link
fair-rose
fair-roseOP7mo ago
I trust you on that
fascinating-indigo
fascinating-indigo7mo ago
😉 however, you cannot build the link to that route as it is not in the route tree yet
fair-rose
fair-roseOP7mo ago
Precisely I mean, I can dynamically I guess
fascinating-indigo
fascinating-indigo7mo ago
not with router standard mechanism i mean
fair-rose
fair-roseOP7mo ago
So it's not like a blocker or anything. Just something that I expected to be available and that would be nice to have.
fascinating-indigo
fascinating-indigo7mo ago
it is not aware of that route
fair-rose
fair-roseOP7mo ago
Yeah it's not aware of that route
fascinating-indigo
fascinating-indigo7mo ago
you could call a server function that throws a redirect to kick off the oauth flow instead of starting it from the API route
fair-rose
fair-roseOP7mo ago
Yup but then it's weird to have the start be a server function and the callback be an API route It's fine, I've built the URL myself Just some feedback + use case to think about
fascinating-indigo
fascinating-indigo7mo ago
yeah

Did you find this page helpful?