-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
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
- Create an API route like
/api/blog/feed
import { createAPIFileRoute } from "@tanstack/react-start/api";
export const APIRoute = createAPIFileRoute("/api/blog/feed")({
GET: async ({ request }) => {
return new Response("Hello! from " + request.url);
},
});- Add a Link element on some view in the app, like this in a footer:
<Link to="/api/blog/feed">RSS Feed</Link> - Visit homepage and then click the 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 the api dir. But the former would be more expected behavior.
Alternatives considered:
- Using a regular
<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. - You might be thinking it's silly to link to RSS feed in footer. Extrapolate the example to other dynamic files like
invoice.pdf, etc.
Expected behavior
.
Screenshots or Videos
No response
Platform
- OS: macOS
- Browser: Chrome, Safari
- Versions
"@tanstack/react-query": "^5.69.0",
"@tanstack/react-router": "^1.114.27",
"@tanstack/react-router-with-query": "^1.114.27",
"@tanstack/react-start": "^1.114.27",Additional context
No response