Skip to content

Infer page navigation query types from the loader’s query schema #883

Open

Description

@karthickeyan-dev

With typed routes enabled, a page loader can validate its query using defineHandler.withValidator({ query: schema }). That gives the loader typed values, but a caller building a link to the same page can still misspell a key or provide a value outside the schema.

What I checked

I ran TypeScript 7.0.2 in strict mode against generated routes in a React Pages app using void@1.11.0 and @void/react@1.11.0. The payments loader validates status against a finite set. Both calls passed:

routeUrl('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/admin/payments', { query: { statsu: 'paid' } })
router.visit({ pathname: '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/admin/payments', query: { status: 'impossible' } })

A nonexistent route path produced the expected type error in the same check. The generated RouteOptions<P> uses one string-keyed RouteQuery for every path, while useRouter().query exposes URLSearchParams.

Request

  • Use the destination loader’s query schema to check structured query keys and values in routeUrl() and router.visit(). Links built with routeUrl() would pick up the same checks.
  • Expose the current page’s validated query values through a typed API. For schemas with defaults or coercions, navigation inputs can differ from the parsed values read by the page.
  • Support a functional update against the previous query so changing a filter can preserve the other filters and reset pagination.

Today each table loader sends its parsed query back as a page prop. The client keeps its own pending query, merges edits and serializes non-default values. A shared schema for reading and navigating would also catch typos in links from other pages.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions