Rick Rick - 1 month ago 7
Javascript Question

React-Router is refreshing page when I follow a route using <a> tag

I'm building a React app that has links pointing to predefined routes.

<a href="/my/react/route/">Click Here</a>


The routes resolve fine, but it's refreshing the page, thereby slowing down app performance. How do I avoid re-rendering the entire page?

Answer

Fix the problem by using the <Link> tag included with react-router.

import React from "react";
import { Link } from 'react-router';

export class ToolTip extends React.Component {
  render() {
    return <Link to="/My/Route"> Click Here </Link>
  }
};