🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
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

1.2.2
Source
npm
Version published
Weekly downloads
171K
-22.25%
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

react

FAQs

Package last updated on 20 Jul 2019

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