Accepted answer

You're doing a few things wrong.

  1. First, browserHistory isn't a thing in V4, so you can remove that.

  2. Second, you're importing everything from react-router, it should be react-router-dom.

  3. Third, react-router-dom doesn't export a Router, instead, it exports a BrowserRouter so you need to import { BrowserRouter as Router } from 'react-router-dom.

Looks like you just took your V3 app and expected it to work with v4, which isn't a great idea.


so if you need want use this code )

import { useRoutes } from "./routes";

import { BrowserRouter as Router } from "react-router-dom";

export const App = () => {

const routes = useRoutes(true);

  return (


      <div className="container">{routes}</div>




// ./routes.js 

import { Switch, Route, Redirect } from "react-router-dom";

export const useRoutes = (isAuthenticated) => {
  if (isAuthenticated) {
    return (
        <Route path="/links" exact>
          <LinksPage />
        <Route path="/create" exact>
          <CreatePage />
        <Route path="/detail/:id">
          <DetailPage />
        <Redirect path="/create" />
  return (
      <Route path={"/"} exact>
        <AuthPage />
      <Redirect path={"/"} />


   appBar: {
    transition: theme.transitions.create(['margin', 'width'], {
      duration: theme.transitions.duration.leavingScreen
    backgroundColor: '#fff' // add the styles here

if you already have appBar at useStyles you can add the styles you just want.


It should be

import {BrowserRouter as Router, Switch, Route} from  'react-router-dom;

Make sure they follow each other in that sequence. That works for me though


location from the useLocation hook or from the useHistory hook is referencing the BrowserRouter from react-router-dom

So only call useLocation and useHistory from children components so this code below will work


import React from "react";
import ReactDOM from "react-dom";
import "./index.css";
import App from "./App";
import { BrowserRouter,Switch, Route, } from "react-router-dom";

           <App />

then in your App.js you can get location by the useLocation hook or useHistory

since it's a child of the BrowserRouter it will be defined

eg. const { location} = useHistory(); eg. const loction = useLocation();


I've tried everything suggested here but didn't work for me. So in case I can help anyone with a similar issue, every single tutorial I've checked is not updated to work with version 4.

Here is what I've done to make it work

import React from 'react';
import App from './App';

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

                <Route path="/" render={()=><App items={temasArray}/>}/>
        </HashRouter >
    ), document.getElementById('root'));

That's the only way I have managed to make it work without any errors or warnings.

In case you want to pass props to your component for me the easiest way is this one:

 <Route path="/" render={()=><App items={temasArray}/>}/>



import { Router, Route, Link, browserHistory } from 'react-router';


import { BrowserRouter as Router, Route } from 'react-router-dom';

It will start working. It is because react-router-dom exports BrowserRouter

Related Query

More Query from same tag