Skip to content

Commit

Permalink
fix: typesafe buildLocation
Browse files Browse the repository at this point in the history
  • Loading branch information
tannerlinsley committed Dec 15, 2023
1 parent 8afcd1a commit 85acbaa
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/react-router/src/RouterProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export type MatchRouteFn<TRouteTree extends AnyRoute> = <
) => false | RouteById<TRouteTree, TResolved>['types']['allParams']

export type BuildLocationFn<TRouteTree extends AnyRoute> = (
opts: BuildNextOptions,
opts: ToOptions<TRouteTree>,
) => ParsedLocation

export type InjectedHtmlEntry = string | (() => Promise<string> | string)
Expand Down
2 changes: 1 addition & 1 deletion packages/react-router/src/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ type BeforeLoadFn<
context: TParentRoute['types']['allContext']
location: ParsedLocation
navigate: NavigateFn<AnyRoute>
buildLocation: BuildLocationFn<AnyRoute>
buildLocation: BuildLocationFn<TParentRoute>
cause: 'preload' | 'enter' | 'stay'
}) => Promise<TRouteContext> | TRouteContext | void

Expand Down
7 changes: 4 additions & 3 deletions packages/react-router/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import {
} from './path'
import invariant from 'tiny-invariant'
import { isRedirect } from './redirects'
import { ToOptions } from './link'
// import warning from 'tiny-warning'

//
Expand Down Expand Up @@ -937,7 +938,7 @@ export class Router<
startTransition,
...rest
}: BuildNextOptions & CommitLocationOptions = {}) => {
const location = this.buildLocation(rest)
const location = this.buildLocation(rest as any)
return this.commitLocation({
...location,
startTransition,
Expand Down Expand Up @@ -1461,9 +1462,9 @@ export class Router<
}

preloadRoute = async (
navigateOpts: BuildNextOptions = this.state.location,
navigateOpts: ToOptions<TRouteTree> = this.state.location as any,
) => {
let next = this.buildLocation(navigateOpts)
let next = this.buildLocation(navigateOpts as any)

let matches = this.matchRoutes(next.pathname, next.search, {
throwOnError: true,
Expand Down

0 comments on commit 85acbaa

Please sign in to comment.