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

react-router-hash-link

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-router-hash-link

Hash link scroll functionality for React Router v4/5

  • 2.4.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
150K
decreased by-16.95%
Maintainers
1
Weekly downloads
 
Created

What is react-router-hash-link?

The react-router-hash-link package is a utility for React Router that allows you to link to specific sections within a page using hash links. It provides smooth scrolling and ensures that the target element is brought into view.

What are react-router-hash-link's main functionalities?

Hash Link Navigation

This feature allows you to create links that navigate to specific sections of the page using hash links. The 'smooth' prop enables smooth scrolling to the target section.


import { HashLink as Link } from 'react-router-hash-link';

function App() {
  return (
    <div>
      <nav>
        <Link smooth to="#section1">Go to Section 1</Link>
        <Link smooth to="#section2">Go to Section 2</Link>
      </nav>
      <div id="section1" style={{ height: '100vh' }}>Section 1</div>
      <div id="section2" style={{ height: '100vh' }}>Section 2</div>
    </div>
  );
}

Custom Scroll Behavior

This feature allows you to define custom scroll behavior when navigating to a hash link. The 'scroll' prop accepts a function that defines how the scrolling should be handled.


import { HashLink as Link } from 'react-router-hash-link';

const customScroll = (el) => {
  el.scrollIntoView({ behavior: 'smooth', block: 'end' });
};

function App() {
  return (
    <div>
      <nav>
        <Link to="#section1" scroll={customScroll}>Go to Section 1</Link>
        <Link to="#section2" scroll={customScroll}>Go to Section 2</Link>
      </nav>
      <div id="section1" style={{ height: '100vh' }}>Section 1</div>
      <div id="section2" style={{ height: '100vh' }}>Section 2</div>
    </div>
  );
}

Other packages similar to react-router-hash-link

Keywords

FAQs

Package last updated on 13 May 2021

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