Skip to content

Commit b65dc1b

Browse files
committed
wouter-preact types are up to date.
1 parent b2949ee commit b65dc1b

File tree

6 files changed

+33
-5
lines changed

6 files changed

+33
-5
lines changed

packages/magazin/components/with-status-code.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ export function WithStatusCode({
1010
const router = useRouter();
1111

1212
// Set status code on SSR context if available
13-
// Cast to any because statusCode is not yet in the official types
1413
if (router.ssrContext) {
15-
(router.ssrContext as any).statusCode = code;
14+
router.ssrContext.statusCode = code;
1615
}
1716

1817
return <>{children}</>;

packages/wouter-preact/types/memory-location.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { BaseLocationHook, Path } from "./location-hook.js";
22

33
type Navigate<S = any> = (
44
to: Path,
5-
options?: { replace?: boolean; state?: S }
5+
options?: { replace?: boolean; state?: S; transition?: boolean }
66
) => void;
77

88
type HookReturnValue = { hook: BaseLocationHook; navigate: Navigate };

packages/wouter-preact/types/router.d.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,21 @@ export type Parser = (
1111
loose?: boolean
1212
) => { pattern: RegExp; keys: string[] };
1313

14+
// Standard navigation options supported by all built-in location hooks
15+
export type NavigateOptions<S = any> = {
16+
replace?: boolean;
17+
state?: S;
18+
/** Enable view transitions for this navigation (used with aroundNav) */
19+
transition?: boolean;
20+
};
21+
22+
// Function that wraps navigate calls, useful for view transitions
23+
export type AroundNavHandler = (
24+
navigate: (to: Path, options?: NavigateOptions) => void,
25+
to: Path,
26+
options?: NavigateOptions
27+
) => void;
28+
1429
// the object returned from `useRouter`
1530
export interface RouterObject {
1631
readonly hook: BaseLocationHook;
@@ -20,9 +35,19 @@ export interface RouterObject {
2035
readonly parser: Parser;
2136
readonly ssrPath?: Path;
2237
readonly ssrSearch?: SearchString;
38+
readonly ssrContext?: SsrContext;
2339
readonly hrefs: HrefsFormatter;
40+
readonly aroundNav: AroundNavHandler;
2441
}
2542

43+
// state captured during SSR render
44+
export type SsrContext = {
45+
// if a redirect was encountered, this will be populated with the path
46+
redirectTo?: Path;
47+
// HTTP status code to set for SSR response
48+
statusCode?: number;
49+
};
50+
2651
// basic options to construct a router
2752
export type RouterOptions = {
2853
hook?: BaseLocationHook;
@@ -31,5 +56,7 @@ export type RouterOptions = {
3156
parser?: Parser;
3257
ssrPath?: Path;
3358
ssrSearch?: SearchString;
59+
ssrContext?: SsrContext;
3460
hrefs?: HrefsFormatter;
61+
aroundNav?: AroundNavHandler;
3562
};

packages/wouter-preact/types/use-browser-location.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const useHistoryState: <T = any>() => T;
1818

1919
export const navigate: <S = any>(
2020
to: string | URL,
21-
options?: { replace?: boolean; state?: S }
21+
options?: { replace?: boolean; state?: S; transition?: boolean }
2222
) => void;
2323

2424
/*

packages/wouter-preact/types/use-hash-location.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Path } from "./location-hook.js";
22

33
export function navigate<S = any>(
44
to: Path,
5-
options?: { state?: S; replace?: boolean }
5+
options?: { state?: S; replace?: boolean; transition?: boolean }
66
): void;
77

88
export function useHashLocation(options?: {

packages/wouter/types/router.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ export interface RouterObject {
4444
export type SsrContext = {
4545
// if a redirect was encountered, this will be populated with the path
4646
redirectTo?: Path;
47+
// HTTP status code to set for SSR response
48+
statusCode?: number;
4749
};
4850

4951
// basic options to construct a router

0 commit comments

Comments
 (0)