44
55export interface NavigateOptions {
66 ignoreBlocker ?: boolean
7+ /** When true, Transitioner should skip calling load() - commitLocation handles it */
8+ skipTransitionerLoad ?: boolean
79}
810
11+ /** Result of a navigation attempt (push/replace) */
12+ export type NavigationResult = { type : 'SUCCESS' } | { type : 'BLOCKED' }
13+
914type SubscriberHistoryAction =
1015 | {
1116 type : Exclude < HistoryAction , 'GO' >
@@ -15,18 +20,27 @@ type SubscriberHistoryAction =
1520 index : number
1621 }
1722
18- type SubscriberArgs = {
23+ export type SubscriberArgs = {
1924 location : HistoryLocation
2025 action : SubscriberHistoryAction
26+ navigateOpts ?: NavigateOptions
2127}
2228
2329export interface RouterHistory {
2430 location : HistoryLocation
2531 length : number
2632 subscribers : Set < ( opts : SubscriberArgs ) => void >
2733 subscribe : ( cb : ( opts : SubscriberArgs ) => void ) => ( ) => void
28- push : ( path : string , state ?: any , navigateOpts ?: NavigateOptions ) => void
29- replace : ( path : string , state ?: any , navigateOpts ?: NavigateOptions ) => void
34+ push : (
35+ path : string ,
36+ state ?: any ,
37+ navigateOpts ?: NavigateOptions ,
38+ ) => Promise < NavigationResult >
39+ replace : (
40+ path : string ,
41+ state ?: any ,
42+ navigateOpts ?: NavigateOptions ,
43+ ) => Promise < NavigationResult >
3044 go : ( index : number , navigateOpts ?: NavigateOptions ) => void
3145 back : ( navigateOpts ?: NavigateOptions ) => void
3246 forward : ( navigateOpts ?: NavigateOptions ) => void
@@ -56,6 +70,21 @@ export type ParsedHistoryState = HistoryState & {
5670 key ?: string // TODO: Remove in v2 - use __TSR_key instead
5771 __TSR_key ?: string
5872 __TSR_index : number
73+ /** Whether to reset scroll position on this navigation (default: true) */
74+ __TSR_resetScroll ?: boolean
75+ /** Session id for cached TSR internals */
76+ __TSR_sessionId ?: string
77+ /** Match snapshot for fast-path on back/forward navigation */
78+ __TSR_matches ?: {
79+ routeIds : Array < string >
80+ params : Record < string , string >
81+ globalNotFoundRouteId ?: string
82+ searchStr ?: string
83+ validatedSearches ?: Array < {
84+ search : Record < string , unknown >
85+ strictSearch : Record < string , unknown >
86+ } >
87+ }
5988}
6089
6190type ShouldAllowNavigation = any
@@ -116,9 +145,14 @@ export function createHistory(opts: {
116145 let location = opts . getLocation ( )
117146 const subscribers = new Set < ( opts : SubscriberArgs ) => void > ( )
118147
119- const notify = ( action : SubscriberHistoryAction ) => {
148+ const notify = (
149+ action : SubscriberHistoryAction ,
150+ navigateOpts ?: NavigateOptions ,
151+ ) => {
120152 location = opts . getLocation ( )
121- subscribers . forEach ( ( subscriber ) => subscriber ( { location, action } ) )
153+ subscribers . forEach ( ( subscriber ) =>
154+ subscriber ( { location, action, navigateOpts } ) ,
155+ )
122156 }
123157
124158 const handleIndexChange = ( action : SubscriberHistoryAction ) => {
@@ -130,11 +164,11 @@ export function createHistory(opts: {
130164 task,
131165 navigateOpts,
132166 ...actionInfo
133- } : TryNavigateArgs ) => {
167+ } : TryNavigateArgs ) : Promise < NavigationResult > => {
134168 const ignoreBlocker = navigateOpts ?. ignoreBlocker ?? false
135169 if ( ignoreBlocker ) {
136170 task ( )
137- return
171+ return { type : 'SUCCESS' }
138172 }
139173
140174 const blockers = opts . getBlockers ?.( ) ?? [ ]
@@ -150,12 +184,13 @@ export function createHistory(opts: {
150184 } )
151185 if ( isBlocked ) {
152186 opts . onBlocked ?.( )
153- return
187+ return { type : 'BLOCKED' }
154188 }
155189 }
156190 }
157191
158192 task ( )
193+ return { type : 'SUCCESS' }
159194 }
160195
161196 return {
@@ -176,10 +211,10 @@ export function createHistory(opts: {
176211 push : ( path , state , navigateOpts ) => {
177212 const currentIndex = location . state [ stateIndexKey ]
178213 state = assignKeyAndIndex ( currentIndex + 1 , state )
179- tryNavigation ( {
214+ return tryNavigation ( {
180215 task : ( ) => {
181216 opts . pushState ( path , state )
182- notify ( { type : 'PUSH' } )
217+ notify ( { type : 'PUSH' } , navigateOpts )
183218 } ,
184219 navigateOpts,
185220 type : 'PUSH' ,
@@ -190,10 +225,10 @@ export function createHistory(opts: {
190225 replace : ( path , state , navigateOpts ) => {
191226 const currentIndex = location . state [ stateIndexKey ]
192227 state = assignKeyAndIndex ( currentIndex , state )
193- tryNavigation ( {
228+ return tryNavigation ( {
194229 task : ( ) => {
195230 opts . replaceState ( path , state )
196- notify ( { type : 'REPLACE' } )
231+ notify ( { type : 'REPLACE' } , navigateOpts )
197232 } ,
198233 navigateOpts,
199234 type : 'REPLACE' ,
0 commit comments