Sometimes, we want to use anchor tags in react-router 4 and JavaScript.
In this article, we’ll look at how to use anchor tags in react-router 4 and JavaScript.
How to use anchor tags in react-router 4 and JavaScript?
To use anchor tags in react-router 4 and JavaScript, we use the eact-router-hash-link
package.
To install it, we run
npm install --save react-router-hash-link
Then we use it by writing
import { HashLink as Link } from "react-router-hash-link";
<Link to="/pathLink#yourAnchorTag">Your link text</Link>;
to import the HashLink
component as Link
.
And then we use it with the to
prop set to the destination URL.
Conclusion
To use anchor tags in react-router 4 and JavaScript, we use the eact-router-hash-link
package.