Created
September 20, 2017 17:38
-
-
Save allilevine/d5a384f75b0c0f4cb665f582d523f233 to your computer and use it in GitHub Desktop.
Anchor / Hash Links and Smooth Scrolling with React Router
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// include React Router Hash Link from https://github.com/rafrex/react-router-hash-link | |
import { HashLink as Link } from 'react-router-hash-link'; | |
// include Smooth Scroll from https://github.com/cferdinandi/smooth-scroll | |
import Scroll from 'smooth-scroll'; | |
class App extends React.Component { | |
componentDidMount() { | |
// initiate smooth scrolling | |
let scroll = new Scroll('a[href*="#"]'); | |
} | |
render() { | |
return ( | |
<div> | |
<Link to="#section">Do the thing</Link> | |
</div> | |
<div id="section">Scroll to here</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment