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•7mo ago
how would that look like?
can you give more details?
fair-roseOP•7mo 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•7mo ago
it does not
i rather meant: why would you want to link to an API route?
fair-roseOP•7mo ago
Google OAuth flow
Well any OAuth flow really
fascinating-indigo•7mo ago
and thats kicked of by the API route?
fair-roseOP•7mo ago
Yup. Basically /api/auth/google redirects to the Google OAuth flow
fascinating-indigo•7mo ago
so you need a hard reload still
you cannot use client side navigation for that
fair-roseOP•7mo 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•7mo ago
so you would need to set
reloadDocument={true}
on that linkfair-roseOP•7mo ago
I trust you on that
fascinating-indigo•7mo ago
😉
however, you cannot build the link to that route as it is not in the route tree
yet
fair-roseOP•7mo ago
Precisely
I mean, I can dynamically I guess
fascinating-indigo•7mo ago
not with router standard mechanism i mean
fair-roseOP•7mo 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•7mo ago
it is not aware of that route
fair-roseOP•7mo ago
Yeah it's not aware of that route
fascinating-indigo•7mo 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-roseOP•7mo 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•7mo ago
yeah