From 32b1e9bd55f7465724964cb13171746521ab9140 Mon Sep 17 00:00:00 2001 From: Tanner Linsley Date: Wed, 16 Nov 2022 15:33:56 -0700 Subject: [PATCH] fix: add location state --- packages/router-core/src/link.ts | 4 +++- packages/router-core/src/router.ts | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/router-core/src/link.ts b/packages/router-core/src/link.ts index 399a770c16..5774ad8451 100644 --- a/packages/router-core/src/link.ts +++ b/packages/router-core/src/link.ts @@ -4,7 +4,7 @@ import { DefaultAllRouteInfo, RouteInfoByPath, } from './routeInfo' -import { Location } from './router' +import { Location, LocationState } from './router' import { Expand, NoInfer, PickAsRequired, PickRequired, Updater } from './utils' export type LinkInfo = @@ -126,6 +126,8 @@ export type ToOptions< to?: ToPathOption // The new has string or a function to update it hash?: Updater + // State to pass to the history stack + state?: LocationState // The source route path. This is automatically set when using route-level APIs, but for type-safe relative routing on the router itself, this is required from?: TFrom // // When using relative route paths, this option forces resolution from the current path, instead of the route API's path or `from` path diff --git a/packages/router-core/src/router.ts b/packages/router-core/src/router.ts index 3575491b57..7d98afbe55 100644 --- a/packages/router-core/src/router.ts +++ b/packages/router-core/src/router.ts @@ -199,6 +199,7 @@ export interface BuildNextOptions { params?: true | Updater> search?: true | Updater hash?: true | Updater + state?: LocationState key?: string from?: string fromCurrent?: boolean @@ -1258,6 +1259,7 @@ export function createRouter< }, { id, + ...next.state, }, ) } else {