router icon indicating copy to clipboard operation
router copied to clipboard

`redirect` Type Error After Upgrade to `v1.168.5`

Open SajiBeats opened this issue 8 months ago • 8 comments

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

  1. Install @tanstack/[email protected]
  2. 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

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.

SajiBeats avatar Mar 27 '26 19:03 SajiBeats

please provide a complete minimal reproducer project

schiller-manuel avatar Mar 27 '26 19:03 schiller-manuel

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.

SajiBeats avatar Mar 28 '26 13:03 SajiBeats

can you share a git repo?

schiller-manuel avatar Mar 28 '26 14:03 schiller-manuel

please provide the reproducer, will close otherwise

schiller-manuel avatar Apr 11 '26 14:04 schiller-manuel

I am getting the same error on @tanstack/[email protected]

rollokd avatar Apr 24 '26 11:04 rollokd

@rollokd can you please provide a complete reproducer project?

schiller-manuel avatar Apr 24 '26 18:04 schiller-manuel

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

rollokd avatar Apr 28 '26 00:04 rollokd

@schiller-manuel did this get resolved?

rollokd avatar Jun 08 '26 01:06 rollokd