Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

warning: failed prop type: the prop `history` is marked as required in `router`, but its value is `undefined`.

// regarding this error 
// warning: failed prop type: the prop `history` is marked as required in
// `router`, but its value is `undefined`.
// If you are using react-router v4 you need to install react-router-dom.
// After that, import BrowserRouter from react-router-dom and switch Router for BrowserRouter.
import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter, Route } from 'react-router-dom'
import App from './components/App';

ReactDOM.render((
     <BrowserRouter>
          <Route path="/" component={App}/>
     </BrowserRouter>
     ),
     document.getElementById('root')
);
// source https://stackoverflow.com/questions/43008036/the-prop-history-is-marked-as-required-in-router-but-its-value-is-undefine


// if you're using react router latest v6
import * as React from "react";
import * as ReactDOM from "react-dom";
import { BrowserRouter } from "react-router-dom";

ReactDOM.render(
  <BrowserRouter>
    {/* The rest of your app goes here */}
  </BrowserRouter>,
  root
);
// source https://reactrouter.com/docs/en/v6/routers/browser-router
 
PREVIOUS NEXT
Tagged: #failed #prop #prop #marked #required
ADD COMMENT
Topic
Name
8+1 =