TIL * 22.03.30

2976 ワード

📛 ERROR


Warning: Failed prop type: The prop `history` is marked as required in `Router`, but its value is `undefined`.
Uncaught TypeError: Cannot read properties of undefined (reading 'location')
The above error occurred in the <Router> component:
Uncaught TypeError: Cannot read properties of undefined (reading 'location')
react-router-domは5.3.0版にインストールされ、使い始めたばかりでエラーが発生しました.
import React from 'react';
import Home from './routes/Home';
import { BrowserRouter, Switch, Route, Router, } from 'react-router-dom';

const App = () => {
  return (
    <Router>
      <Switch>
        <Route path="/">
          <Home />
        </Route>
      </Switch>
    </Router>
  );
}

export default App;
ご覧のように、コードにはhistorylocationは使用されていません.
import { BrowserRouter as Router, Route, Switch } from "react-router-dom";
importは上記のように解決できます!
v 6を使うときに見たことのない間違いのようで、パニックになりました.
関連項目:https://stackoverflow.com/questions/42892488/react-router-v4-0-0-uncaught-typeerror-cannot-read-property-location-of-unde