TanStackT
TanStack2y ago
26 replies
wet-aqua

How do I stop search params from being automatically converted to number?

In validateSearch, a search param that's alphanumeric is coming in as a number if there are no letters in the value. Is this expected? My input validation with Valibot rejects it because of that.

I really wouldn't expect the router to do anything with the value before validateSearch runs.

For example, using URL the value is parsed as a string, not number.

window.location.href // 'http://localhost:3000?code=123'
new URL(window.location.href).searchParams.get('code') // '123' (string)

export const Route = createFileRoute('/')({
  validateSearch(search) {
    search.code // 123 (number)  
  }
})
Was this page helpful?