React router giving me cannot read property of location undefined. (react-router-dom version 5.2.0)

I have been looking all over and cant figure out why this is happening. I’ve been seeing all different answers. Here is my App.js:

import React, { useState } from "react";
import "./App.css";
import Hero from "./Hero";
import Home from "./pages/Home";
import Store from "./pages/Store";
import { BrowserRouter as Router, Switch, Route } from "react-router-dom";

function App() {
  return (
    <>
      <Router>
        <Hero />
        <Switch>
          <Route path="/" exact component={Home} />
          <Route path="/store" exact component={Store} />
        </Switch>
      </Router>
    </>
  );
}

export default App;

here is the code for my menu containing links:

import React from "react";
import { Link, Router } from "react-router-dom";
import "./Menu.css";

function Menu() {
  return (
    <Router>
      <div className="menuCont">
        <ul className="menuList">
          <li className="menuItem">
            <Link to="/">
              <div>
                <h1 className="menuText">Home</h1>
              </div>
            </Link>
          </li>
          <li className="menuItem">
            <Link to="/store">
              <div>
                <h1 className="menuText">Store</h1>
              </div>
            </Link>
          </li>
          <li className="menuItem">
            <Link to="/">
              <div>
                <h1 className="menuText">Contact</h1>
              </div>
            </Link>
          </li>
          <li className="menuItem">
            <Link to="/">
              <div>
                <h1 className="menuText">About</h1>
              </div>
            </Link>
          </li>
        </ul>
      </div>
    </Router>
  );
}

export default Menu;

I have been unable to get a good answer that works for me. This behavior seems unpredictable especially since this code is pretty much the same as i used in another app i made. Also typing in /store into the url brings me to the store page so i have no clue what is happening im not super familiar with the router.

1 thought on “React router giving me cannot read property of location undefined. (react-router-dom version 5.2.0)”

  1. Well sheesh talk about unpredictable behavior i reinstalled react-router-dom only this time i specified npm install react-router-dom@5 and it worked I may never know wtf just happened. Im sorry i can’t provide a more detailed description. It is possible the current release is messed up. I really dont know

    Reply

Leave a Comment