-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Open
Description
Which project does this relate to?
Router
Describe the bug
API routes without a GET handler doesn't return a 404 status code by default but return 200 OK, with an error in the console:
{
"data": {
"name": "Error",
"message": "Invariant failed: Expected to find a match below the root match in SPA mode.",
"stack": "Error: Invariant failed: Expected to find a match below the root match in SPA mode.\n at invariant (http://localhost:3000/node_modules/.pnpm/tiny-invariant@1.3.3/node_modules/tiny-invariant/dist/esm/tiny-invariant.js?v=c5ed1ad0:12:9)\n at hydrate (http://localhost:3000/node_modules/.pnpm/@tanstack+router-core@1.132.47/node_modules/@tanstack/router-core/dist/esm/ssr/ssr-client.js?v=c5ed1ad0:141:5)\n at async hydrateStart (http://localhost:3000/node_modules/.pnpm/@tanstack+start-client-core@1.132.54/node_modules/@tanstack/start-client-core/dist/esm/client/hydrateStart.js?t=1760429159805&v=c5ed1ad0:29:5)"
},
"__isServerError": true
}
Route API without a GET handler:
import { createFileRoute } from '@tanstack/react-router';
export const Route = createFileRoute('/api/test-no-get')({
server: {
handlers: {
POST: () => {
return new Response('ok', { status: 200 });
},
},
},
});Your Example Website or App
https://stackblitz.com/edit/github-zlbrcubx-vwhcvwvk?file=src%2Froutes%2Fapi%2Ftest-no-get.ts
Steps to Reproduce the Bug or Issue
- Create an API route without a GET handler.
- Access the API.
- Check the console and status code.
Expected behavior
It should return a 404 status code to avoid confusing search engines.
Screenshots or Videos
No response
Platform
- Router / Start Version: 1.132.47 / 1.132.56
- OS: Windows
- Browser: Chrome
- Browser Version: 141.0.7390.77
- Bundler: Vite
- Bundler Version: 7.1.9
Additional context
No response
Metadata
Metadata
Assignees
Labels
No labels