Skip to content

Commit a22d7d2

Browse files
committed
fix preloadRoute to take string path
1 parent 6dd0473 commit a22d7d2

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

.changeset/four-seahorses-live.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solidjs/router": patch
3+
---
4+
5+
fix preloadRoute to take string path

src/data/events.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export function setupNativeEvents(
7878
if (!res) return;
7979
const [a, url] = res;
8080
transformUrl && (url.pathname = transformUrl(url.pathname));
81-
router.preloadRoute(url, { preloadData: a.getAttribute("preload") !== "false" });
81+
router.preloadRoute(url, a.getAttribute("preload") !== "false");
8282
}
8383

8484
function handleAnchorMove(evt: Event) {
@@ -89,7 +89,7 @@ export function setupNativeEvents(
8989
if (lastElement === a) return;
9090
transformUrl && (url.pathname = transformUrl(url.pathname));
9191
preloadTimeout = setTimeout(() => {
92-
router.preloadRoute(url, { preloadData: a.getAttribute("preload") !== "false" });
92+
router.preloadRoute(url, a.getAttribute("preload") !== "false");
9393
lastElement = a;
9494
}, 20) as any;
9595
}

src/routing.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ export const useHref = (to: () => string | undefined) => {
7777
export const useNavigate = () => useRouter().navigatorFactory();
7878
export const useLocation = <S = unknown>() => useRouter().location as Location<S>;
7979
export const useIsRouting = () => useRouter().isRouting;
80-
export const usePreloadRoute = () => useRouter().preloadRoute;
80+
export const usePreloadRoute = () => {
81+
const pre = useRouter().preloadRoute
82+
return (url: string | URL, options: { preloadData?: boolean } = {} ) =>
83+
pre(url instanceof URL ? url : new URL(url, mockBase), options.preloadData)
84+
}
8185

8286
export const useMatch = <S extends string>(path: () => S, matchFilters?: MatchFilters<S>) => {
8387
const location = useLocation();
@@ -470,7 +474,7 @@ export function createRouterContext(
470474
}
471475
}
472476

473-
function preloadRoute(url: URL, options: { preloadData?: boolean } = {}) {
477+
function preloadRoute(url: URL, preloadData?: boolean) {
474478
const matches = getRouteMatches(branches(), url.pathname);
475479
const prevIntent = intent;
476480
intent = "preload";
@@ -481,7 +485,7 @@ export function createRouterContext(
481485
(route.component as MaybePreloadableComponent).preload!();
482486
const { preload } = route;
483487
inPreloadFn = true;
484-
options.preloadData &&
488+
preloadData &&
485489
preload &&
486490
runWithOwner(getContext!(), () =>
487491
preload({

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ export interface RouterContext {
172172
renderPath(path: string): string;
173173
parsePath(str: string): string;
174174
beforeLeave: BeforeLeaveLifecycle;
175-
preloadRoute: (url: URL, options: { preloadData?: boolean }) => void;
175+
preloadRoute: (url: URL, preloadData?: boolean) => void;
176176
singleFlight: boolean;
177177
submissions: Signal<Submission<any, any>[]>;
178178
}

0 commit comments

Comments
 (0)