Script loading for React Router applications with data and framework modes
createBrowserRouter
with loadersserver-tag-react-router
in “Data Mode” requires a custom server-side rendering (SSR) setup. The serverTagLoader
is designed to run exclusively on the server.
ServerTag
offers a powerful and seamless way to manage both global and per-route scripts.
Simply place the <ServerTag />
component once in your root layout. It will automatically detect and render scripts loaded from any active route’s loader, from the root down to the deepest child.
<ServerTag />
in the <head>
of your root layout. This single component will handle rendering all scripts.
serverTagLoader
is spread into the final returned object from your loader.
Prop | Type | Default | Description |
---|---|---|---|
async | boolean | true | Toggles the async attribute on the script tag. |
renderScript | function | undefined | Custom script rendering function. |
serverTagLoader(config)
config.remoteUrl
(string, required): The URL to fetch script URLs fromconfig.cacheInterval
(number, optional): Cache duration in seconds (default: 300)Promise<ServerTagLoaderData>
Usage Examples: