Which project does this relate to?
Router
Describe the bug
In commit 2f53749 (shipped in @tanstack/react-router@1.170.10), error.routerCode was removed from the error passed to a route's onError handler. Previously, search/param validation failures could be detected like this:
export const Route = createFileRoute('/')({
component: RouteComponent,
params: pathParamsSchema, // Using Zod (v4) schema
validateSearch: searchParamsSchema, // Using Zod (v4) schema
....
onError: (error) => {
if (error.routerCode === 'PARSE_PARAMS') throw redirect({ to: '/parse-error' })
if (error.routerCode === 'VALIDATE_SEARCH') throw redirect({ to: '/validation-error' })
throw error
}
}
This now silently breaks because routerCode no longer exists. I would say this change is more of a breaking change as the contract has changed, but I'm unsure if it is intentional or just a bug.
Looking at the code base (guessing the change is intentionally) a possible solution to have the minimum changes and exact functionality could be:
onError: (error) => {
if (error instanceof PathParamError) throw redirect({ to: '/' })
if (error instanceof SearchParamError) throw redirect({ to: '/' })
throw error
}
However,@tanstack/react-router only re-exports SearchParamError, not PathParamError it is only exported from @tanstack/router-core, forcing consumers to import from a transitive dependency (maybe is not but most likely yes):
import { SearchParamError } from '@tanstack/react-router'; // ✅ works
import { PathParamError } from '@tanstack/react-router'; // ❌ not exported
import { PathParamError } from '@tanstack/router-core'; // works, but most likely reaching into a transitive dep
Expected behavior
Either have routerCode back or re-export PathParamError from @tanstack/react-router alongside SearchParamError, so consumers don't have to import from @tanstack/router-core (which most likely is going to be a transitive dep).
If that's not correct then docs should explain the proper way to differentiate between a parse error and a validation error is provided.
Platform
- Router / Start Version:
@tanstack/react-router 1.170.11 (@tanstack/router-core 1.171.9, @tanstack/router-plugin 1.168.14)
- OS: Any
- Browser: Any
- Browser Version: Any
- Bundler: vite
- Bundler Version: 8.0.16
Additional context
Maybe the usage of error instanceOf PathParamError or error instanceOf SearchParamError is not a good solution so in that case what would be a good solution?
Side note: the documentation still references the removed routerCode in Search Params guide
Which project does this relate to?
Router
Describe the bug
In commit
2f53749(shipped in@tanstack/react-router@1.170.10),error.routerCodewas removed from the error passed to a route'sonErrorhandler. Previously, search/param validation failures could be detected like this:This now silently breaks because
routerCodeno longer exists. I would say this change is more of a breaking change as the contract has changed, but I'm unsure if it is intentional or just a bug.Looking at the code base (guessing the change is intentionally) a possible solution to have the minimum changes and exact functionality could be:
However,
@tanstack/react-routeronly re-exportsSearchParamError, notPathParamErrorit is only exported from@tanstack/router-core, forcing consumers to import from a transitive dependency (maybe is not but most likely yes):Expected behavior
Either have
routerCodeback or re-exportPathParamErrorfrom@tanstack/react-routeralongsideSearchParamError, so consumers don't have to import from@tanstack/router-core(which most likely is going to be a transitive dep).If that's not correct then docs should explain the proper way to differentiate between a parse error and a validation error is provided.
Platform
@tanstack/react-router1.170.11 (@tanstack/router-core1.171.9,@tanstack/router-plugin1.168.14)Additional context
Maybe the usage of
error instanceOf PathParamErrororerror instanceOf SearchParamErroris not a good solution so in that case what would be a good solution?Side note: the documentation still references the removed
routerCodein Search Params guide