react router link href code example

Example 1: link tag react

{user.name}
// becomes one of these depending on your History and if the route is
// active
Michael
Michael

// change the activeClassName
{user.name}

// change style when link is active
Users

Example 2: react router link

import React from "react";
import ReactDOM from "react-dom";
import {
  BrowserRouter as Router,
  Switch,
  useLocation
} from "react-router-dom";

function usePageViews() {
  let location = useLocation();
  React.useEffect(() => {
    ga.send(["pageview", location.pathname]);
  }, [location]);
}

function App() {
  usePageViews();
  return ...;
}

ReactDOM.render(
  
    
  ,
  node
);

Example 3: react router link

import React from "react";
import ReactDOM from "react-dom";
import { createBrowserHistory } from "history";

const customHistory = createBrowserHistory();

ReactDOM.render(, node);

Tags:

Misc Example