react router link to component code example

Example 1: react router Link does work

import { Link } from 'react-router-dom';

Example 2: Link react router

<Link to="/about">About</Link>

Example 3: react routes

npm install react-router-dom

Example 4: link in react

<Link
  to={{
    pathname: "/courses",
    search: "?sort=name",
    hash: "#the-hash",
    state: { fromDashboard: true }
  }}
/>

Example 5: route in component react

import { BrowserRouter, Route, Link } from "react-router-dom";

Example 6: how to link to a different component in reactjs without react router

const showComponent = (route, component) => {
  return window.location.pathname === route ? component : null
}