Categories
JavaScript Answers

How to use anchor tags in react-router 4 and JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *