React Router Scroll Management

0.4.4 · abandoned · verified Tue Apr 21

react-router-scroll is a middleware for React Router versions 2.x and 3.x, providing advanced scroll management capabilities for web applications. It allows developers to customize scroll behavior during route transitions, enabling features like scrolling to the top of the page, to specific pixel coordinates, or to named HTML elements based on routing events. The library internally uses `scroll-behavior` for its core functionality. The current stable version is 0.4.4, with the last notable release in 2017. Due to fundamental changes in React Router v4 and subsequent versions (which removed the router middleware concept), this library is not compatible with modern React Router setups. It is considered abandoned for new projects utilizing React Router v4, v5, or v6, with no active development or planned compatibility updates for newer React Router APIs.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates basic setup for `react-router-scroll` with React Router v2/v3, applying `useScroll` as a router middleware to manage default browser-style scroll behavior on route transitions.

import React from 'react';
import ReactDOM from 'react-dom';
import { applyRouterMiddleware, browserHistory, Router } from 'react-router';
import { useScroll } from 'react-router-scroll';

// Define your routes (example)
const routes = {
  path: '/',
  component: ({ children }) => (
    <div>
      <h1>Welcome</h1>
      {children}
    </div>
  ),
  indexRoute: { component: () => <p>Home Page Content</p> },
  childRoutes: [
    { path: 'about', component: () => <p>About Us Content</p> },
    { path: 'contact', component: () => <p>Contact Us Content</p> }
  ]
};

ReactDOM.render(
  <Router
    history={browserHistory}
    routes={routes}
    render={applyRouterMiddleware(useScroll())}
  />,
  document.getElementById('root')
);

view raw JSON →