Skip to content
Source
Sign inSign up
TanStack/router

Invalid route is accepted #2267

Send to my agent
Closedarackaf(GitHub profile, opens in a new tab) opened this issue 8 comments

Which 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

  1. is it on purpose that you do not have a "root" index.tsx?

  2. "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

  3. 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.

  4. SeanCassiere added labelsbug

  5. SeanCassiere closed this

  6. @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

  7. SeanCassiere reopened this

  8. SeanCassierecommented

    @arackaf perhaps your ts was lagging? Updating to latest, the <Link to='/'> correctly errors out since the to='/' does not exist

    Image

    Image

    Image

  9. SeanCassiere added labelsinformation needed

  10. Hmm weird. So, I'm in branch special/temp-tsc-quirk

    I'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 dev I see no error in the Link for

    <Link to="/" className="[&.active]:font-bold">
      Home
    </Link>

    To be 100% certain I did run npx tsc and it ran fine without error.

    And to verify that, I changed the Link to value to to="/X" which errors in the ide, and also when running npx tsc

    So that <Link to an invalid url of "/" does seem to be getting accepted currently

  11. @arackaf Figured out the issue. Your @tanstack/router-vite-plugin is quite old. Upgrading the plugin and regenerating the route tree (running npm 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 😅.

  12. SeanCassiere removed labelsinformation needed

  13. Aha! I never thought to upgrade the Vite plugin. All good now, of course. Thank you!

Sign in to join this conversation.