Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gatsby-react-router-scroll

Package Overview
Dependencies
Maintainers
13
Versions
359
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gatsby-react-router-scroll

React Router scroll management forked from https://github.com/ytase/react-router-scroll for Gatsby

  • 6.13.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
203K
decreased by-21.65%
Maintainers
13
Weekly downloads
 
Created

What is gatsby-react-router-scroll?

The gatsby-react-router-scroll package is designed to manage scroll behavior in Gatsby applications. It provides a way to control how the page scrolls when navigating between routes, ensuring a smooth user experience.

What are gatsby-react-router-scroll's main functionalities?

Scroll Restoration

This feature allows you to wrap your Router component with ScrollContext to enable scroll restoration. This means that when users navigate back to a previous page, the scroll position will be restored to where they left off.

import { Router } from '@reach/router';
import { ScrollContext } from 'gatsby-react-router-scroll';

const App = () => (
  <ScrollContext>
    <Router>
      <Home path="/" />
      <About path="/about" />
    </Router>
  </ScrollContext>
);

Custom Scroll Behavior

This feature allows you to define custom scroll behavior by passing a function to the scrollBehavior prop of ScrollContext. This function can be used to customize how the scroll position is handled when navigating between routes.

import { Router } from '@reach/router';
import { ScrollContext } from 'gatsby-react-router-scroll';

const customScrollBehavior = ({ routerProps: { location }, getSavedScrollPosition }) => {
  const savedPosition = getSavedScrollPosition(location);
  window.scrollTo(...(savedPosition || [0, 0]));
};

const App = () => (
  <ScrollContext scrollBehavior={customScrollBehavior}>
    <Router>
      <Home path="/" />
      <About path="/about" />
    </Router>
  </ScrollContext>
);

Other packages similar to gatsby-react-router-scroll

Keywords

FAQs

Package last updated on 23 Jan 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc