Skip to content

Commit 8760827

Browse files
committed
Clean up router navigate/fetch argument types
1 parent 13e6b8e commit 8760827

File tree

1 file changed

+29
-15
lines changed

1 file changed

+29
-15
lines changed

packages/router/router.ts

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export interface Router {
147147
key: string,
148148
routeId: string,
149149
href: string | null,
150-
opts?: RouterNavigateOptions
150+
opts?: RouterFetchOptions
151151
): void;
152152

153153
/**
@@ -418,14 +418,26 @@ export interface GetScrollPositionFunction {
418418

419419
export type RelativeRoutingType = "route" | "path";
420420

421-
type BaseNavigateOptions = {
422-
replace?: boolean;
423-
state?: any;
421+
type BaseNavigateOrFetchOptions = {
422+
fromRouteId?: string;
424423
preventScrollReset?: boolean;
425424
relative?: RelativeRoutingType;
426-
fromRouteId?: string;
427425
};
428426

427+
type BaseNavigateOptions = BaseNavigateOrFetchOptions & {
428+
replace?: boolean;
429+
state?: any;
430+
};
431+
432+
type BaseSubmissionOptions = {
433+
formMethod?: HTMLFormMethod;
434+
formEncType?: FormEncType;
435+
action?: ActionFunction;
436+
} & (
437+
| { formData: FormData; payload?: undefined }
438+
| { formData?: undefined; payload: any }
439+
);
440+
429441
/**
430442
* Options for a navigate() call for a Link navigation
431443
*/
@@ -434,13 +446,7 @@ type LinkNavigateOptions = BaseNavigateOptions;
434446
/**
435447
* Options for a navigate() call for a Form navigation
436448
*/
437-
type SubmissionNavigateOptions = BaseNavigateOptions & {
438-
formMethod?: HTMLFormMethod;
439-
formEncType?: FormEncType;
440-
} & (
441-
| { formData: FormData; payload?: undefined }
442-
| { formData?: undefined; payload: any }
443-
);
449+
type SubmissionNavigateOptions = BaseNavigateOptions & BaseSubmissionOptions;
444450

445451
/**
446452
* Options to pass to navigate() for either a Link or Form navigation
@@ -449,12 +455,20 @@ export type RouterNavigateOptions =
449455
| LinkNavigateOptions
450456
| SubmissionNavigateOptions;
451457

458+
/**
459+
* Options for a navigate() call for a Link navigation
460+
*/
461+
type LoadFetchOptions = BaseNavigateOrFetchOptions;
462+
463+
/**
464+
* Options for a navigate() call for a Form navigation
465+
*/
466+
type SubmitFetchOptions = BaseNavigateOrFetchOptions & BaseSubmissionOptions;
467+
452468
/**
453469
* Options to pass to fetch()
454470
*/
455-
export type RouterFetchOptions =
456-
| Omit<LinkNavigateOptions, "replace">
457-
| Omit<SubmissionNavigateOptions, "replace">;
471+
export type RouterFetchOptions = LoadFetchOptions | SubmitFetchOptions;
458472

459473
/**
460474
* Potential states for state.navigation

0 commit comments

Comments
 (0)