`redirect` Type Error After Upgrade to `v1.168.5`
Which project does this relate to?
Router
Describe the bug
Package: @tanstack/react-router
Versions affected: 1.168.5 (works in 1.166.3)
After upgrading @tanstack/react-router from 1.166.3 to 1.168.5, the redirect function no longer accepts href alone for external redirects.
Previously, external redirects worked correctly using:
if (condition) {
redirect({ href: "http://external.com", throw: true });
}
However, after upgrading, TypeScript raises an error indicating that the to property is required.
Your Example Website or App
N/A — reproducible by installing @tanstack/[email protected] and running tsc --noEmit on the route file that contains redirect function.
Steps to Reproduce the Bug or Issue
- Install
@tanstack/[email protected] - Use:
redirect({ href: "http://external.com", throw: true });
→ Works fine
3. Upgrade to @tanstack/[email protected]
4. Same code now results in a TypeScript error requiring to
Expected behavior
The redirect function should continue to support external redirects using only the href property (as in previous versions), or at least not require to when href is provided.
Screenshots or Videos
TypeScript error:
Property 'to' is missing in type '{ href: string; throw: true; }'
This suggests that to is now required even when performing an external redirect with href.
Platform
- Router / Start Version:
@tanstack/[email protected]/@tanstack/[email protected] - Bundler:
[email protected]
Additional context
The upgrade was done to use the new server handlers feature:
createRouteFile("/path")({
server: {
handlers: {}
}
})
This works as expected, but introduces the redirect typing issue.
please provide a complete minimal reproducer project
I’ve updated the description with additional details and reproduction steps using a local setup (installing the package and running tsc --noEmit). Unfortunately, I don’t have a live example app for this case, but the issue should be reproducible with those steps. Happy to provide more info if needed.
can you share a git repo?
please provide the reproducer, will close otherwise
I am getting the same error on @tanstack/[email protected]
@rollokd can you please provide a complete reproducer project?
@schiller-manuel that's my mistake I actually misread this, but I'm getting an identical error when using href on a Link, here is the minimal repro made using the tanstack cli for router only, with the latest tanstack react router version, https://github.com/rollokd/tanstack-link-href-repro, the error is on a link in src/routes/index.tsx. Hope this helps.
@schiller-manuel did this get resolved?