usePreloadRoute

usePreloadRoute returns a function for manually preloading a route.


Import

import { usePreloadRoute } from "@solidjs/router";

Type

function usePreloadRoute(): (
url: string | URL,
options?: { preloadData?: boolean }
) => void;

Parameters

usePreloadRoute takes no arguments.


Return value

  • Type: (url: string | URL, options?: { preloadData?: boolean }) => void

Returns a function that preloads the matching route for a URL.

url

  • Type: string | URL
  • Required: Yes

URL or URL string to preload.

options

  • Type: { preloadData?: boolean }
  • Required: No

A configuration object with the following properties:

preloadData

  • Type: boolean
  • Default: false

When true, triggers the route's data loading in addition to preloading the route itself.


Return value

None.


Examples

Basic usage

import { usePreloadRoute } from "@solidjs/router";
function SettingsButton() {
const preload = usePreloadRoute();
return (
<button onClick={() => preload("/users/settings", { preloadData: true })}>
Load settings
</button>
);
}

Last updated: 5/6/26, 4:10 AMEdit this pageReport an issue with this page