Invalid route is accepted #2267
Send to my agentWhich project does this relate to?#
Router
Describe the bug#
Repro: https://github.com/arackaf/tanstack-router-routing-demo/tree/special/temp-tsc-quirk (note the branch - special/temp-tsc-quirk)
Clone. npm i. Then run npx tsc
It should succeed even though the root route has this
<Link to="/" className="[&.active]:font-bold">
Home
</Link>
which does not have a corresponding, matching route. The default "Not found" is rendered for the Outlet. Oddly, if you delete tasks.index.ts, then ts now correctly errors on that Link
Your Example Website or App#
https://github.com/arackaf/tanstack-router-routing-demo/tree/special/temp-tsc-quirk
Steps to Reproduce the Bug or Issue#
See above
Expected behavior#
Should error
Screenshots or Videos#
n/a
Platform#
- OS: Mac
- Browser: n/a
- Version: n/a
- TS: 5.5.4
Additional context#
n/a
"Sort of" - I'm basically just poking around, getting ready to blog about Router. Deleted some routes to make sure I'd get TS errors, and was surprised when I didn't - hence the issue
I've upgraded the version to the latest and can now confirm that the
<Link to='/'>does indeed throw an error during build time now.SeanCassiere added labelsbug
SeanCassiere closed this
@SeanCassiere fyi I upgraded the repro above to @tanstack/react-router - 1.58.3 but I'm still seeing the same invalid Link url get accepts
SeanCassiere reopened this
@arackaf perhaps your ts was lagging? Updating to latest, the
<Link to='/'>correctly errors out since theto='/'does not existSeanCassiere added labelsinformation needed
Hmm weird. So, I'm in branch
special/temp-tsc-quirkI've upgraded TypeScript and react-router. All my deps look like this
"dependencies": { "@tanstack/react-query": "^5.52.1", "@tanstack/react-router": "^1.58.3", "@tanstack/router-cli": "^1.58.1", "react": "^18.3.1", "typescript": "^5.6.2" }, "devDependencies": { "@tanstack/router-devtools": "^1.35.3", "@tanstack/router-vite-plugin": "^1.35.4", "@types/react": "^18.3.5", "@types/react-dom": "^18.3.0" }When I run
npm run devI see no error in the Link for<Link to="/" className="[&.active]:font-bold"> Home </Link>To be 100% certain I did run
npx tscand it ran fine without error.And to verify that, I changed the Link
tovalue to to="/X" which errors in the ide, and also when runningnpx tscSo that <Link to an invalid url of
"/"does seem to be getting accepted currently@arackaf Figured out the issue. Your
@tanstack/router-vite-pluginis quite old. Upgrading the plugin and regenerating the route tree (runningnpm run dev) fixes the issue.The changes made for https://tanstack.com/blog/tanstack-router-typescript-performance, are needed when using file-based routing with your newer version of TSR.
I didn't notice it earlier because whenever I upgrade packages I tend to do them all at once 😅.
SeanCassiere removed labelsinformation needed
Aha! I never thought to upgrade the Vite plugin. All good now, of course. Thank you!
arackaf(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
is it on purpose that you do not have a "root" index.tsx?