-
-
Notifications
You must be signed in to change notification settings - Fork 876
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Start: Client-side router cannot navigate to API route #3931
Comments
This is expected behaviour, since the API routes are not navigatable routes via the router. Even if you force this navigation using the Router, you'd have to use the You should be using the native anchor element for this. <Link to='/blog'>Blog Route</Link>
<a href='/api/blog/stuff>External route</a> |
Expected behavior currently, but a small headache DX wise. For example, if you're rendering a list of links from an array, likely passed as a prop to a component, your template now must contain conditional logic to use an (My perspective is coming from SvelteKit where this "just works" irrespective of the link destination.) Low priority since there is an easy workaround |
is this a typesafe link there? |
No, but that's orthogonal given it should be possible to make it typesafe here for API routes. There are much higher priorities for Tanstack right now. Just creating the issue to note a DX rough edge to consider down the road. |
we are currently reworking API routes while migrating off vinxi, and we discussed exactly this. Since for API routes we won't have router level path and search param validation, a fully typesafe link won't be possible. We decided not to bring in API routes into |
Which project does this relate to?
Start
Describe the bug
Clicking a
Link
element that points to an API route always returns "Route not found".Your Example Website or App
.
Steps to Reproduce the Bug or Issue
/api/blog/feed
<Link to="/api/blog/feed">RSS Feed</Link>
Actual behavior:
Route not found
is shown in the UI.(Hard refreshing when on
/api/blog/feed
or visiting it directly in the browser loads it, b/c the route itself is working properly.)Expected behavior:
The server side route's contents should be displayed after clicking a Link to it.
Notes:

The Link element does not find any API/server-side route in its types
Solutions would be to 1.) include all API routes in the types, 2.) only includes API routes that are outside the
/api
dir, if you wanted to not include all of API routes in the types, when TanstackStart supports locating API routes outside theapi
dir. But the former would be more expected behavior.Alternatives considered:
<a href="/api/blog/feed">RSS</a>
works. I'll use this for now. But 1.) the link will not benefit from Link's prefetching, 2.) it complicates the DX to need to handle links differently depending on if they link to a view or a server side route.invoice.pdf
, etc.Expected behavior
.
Screenshots or Videos
No response
Platform
Additional context
No response
The text was updated successfully, but these errors were encountered: