ScrollRestoration

ScrollRestoration

Summary

Reference Documentation ↗

Emulates the browser's scroll restoration on location changes. Apps should only render one of these, right before the Scripts component.

import { ScrollRestoration } from "react-router";

export default function Root() {
  return (
    <html>
      <body>
        <ScrollRestoration />
        <Scripts />
      </body>
    </html>
  );
}

This component renders an inline <script> to prevent scroll flashing. The nonce prop will be passed down to the script tag to allow CSP nonce usage.

<ScrollRestoration nonce={cspNonce} />

Props

ScriptsProps

A couple common attributes:

You cannot pass through attributes such as async, defer, src, type, noModule because they are managed by React Router internally.

Docs and examples CC 4.0