router icon indicating copy to clipboard operation
router copied to clipboard

Relative navigation always expects a `search` param?

Open melv-n opened this issue 1 year ago • 4 comments

Describe the bug

When using navigation (e.g. navigate / redirect) with a from and relative to, it seems TypeScript always complains about the search param being required, even if none of the routes define a validateSearch.

This example works at runtime, but TypeScript complains:

export const Route = createFileRoute('/posts/$postId')({
  beforeLoad: () => {
      // works, but TypeScript error about required "search" param
      throw redirect({
        from: Route.fullPath,
        to: '../',
      });
  }
});

Your Example Website or App

https://stackblitz.com/edit/tanstack-router-ycpp7o?file=src%2Froutes%2Fposts.%24postId.tsx

Steps to Reproduce the Bug or Issue

  1. Open the posts.$postId.tsx file and go to the render function
  2. Observe there's a TypeScript error, even though the actual code works

Expected behavior

I expect that if the to route doesn't provide a validateSearch, it's not a required prop and TypeScript doesn't complain.

Screenshots or Videos

CleanShot 2024-06-27 at 11 06 30@2x

Platform

  • OS: macOS / Arc

Additional context

No response

melv-n avatar Jun 27 '24 09:06 melv-n