react-router's <Router> history prop expect properties missing from history's BrowserHistory
See original GitHub issueI’m running into a problem using react-router
s low level <Router>
component with history
’s BrowserHistory
. The history
prop for <Router>
is expected to be a RouterHistory
which includes canGo
, entries
and index
not present in BrowserHistory
.
import { Router } from "react-router-dom"
import createBrowserHistory from "history/createBrowserHistory"
const history = createBrowserHistory()
const Provider = ({ children }) => <Router history={history}>{children}</Router>
This yields the following:
Cannot create Router element because:
• property canGo is missing in BrowserHistory [1] but exists in RouterHistory [2] in property history.
• property entries is missing in BrowserHistory [1] but exists in RouterHistory [2] in property history.
• property index is missing in BrowserHistory [1] but exists in RouterHistory [2] in property history.
• string [3] is incompatible with undefined [4] in property key of the first argument of the first argument of
property history.block.
• string [5] is incompatible with undefined [6] in property state of the first argument of the first argument of
property history.block.
• string [7] is incompatible with boolean [8] in the return value of the first argument of property history.block.
• string [3] is incompatible with undefined [4] in property history.location.key.
• string [5] is incompatible with undefined [6] in property history.location.state.
• string [9] is incompatible with LocationShape [10] in the first argument of property history.push.
• string [11] is incompatible with LocationShape [12] in the first argument of property history.replace.
• array type [13] is incompatible with undefined [14] in the second argument of property history.replace.
flow-typed/npm/history_v4.x.x.js
[5] 14│ state: string,
[3] 15│ key: string,
:
[11][13] 23│ replace: (path: string, Array<mixed>) => void,
:
[7] 29│ block: ((location: BrowserLocation, action: Action) => string) => Unblock,
[9] 30│ push: (path: string) => void,
:
[1] 42│ declare export default (opts?: HistoryOpts) => BrowserHistory;
flow-typed/npm/react-router-dom_v4.x.x.js
[6] 44│ state?: any,
[4] 45│ key?: string
:
[10] 64│ push(path: string | LocationShape, state?: any): void,
[12][14] 65│ replace(path: string | LocationShape, state?: any): void,
:
[8] 71│ callback: (location: Location, action: HistoryAction) => boolean
:
[2] 116│ history: RouterHistory,
Issue Analytics
- State:
- Created 6 years ago
- Reactions:7
- Comments:9 (4 by maintainers)
Top Results From Across the Web
React Router DOM's Router doesn't accept history correctly
The problem should be the missing length , goBack , and goForward properties from the memory history. Is it a bug with react-router...
Read more >History - React Router: Declarative Routing for React.js
“browser history” - A DOM-specific implementation, useful in web browsers that ... history objects typically have the following properties and methods:.
Read more >React Router breaking with TS? - The freeCodeCamp Forum
Hey guys, I have an issue accessing the history prop in my Header component that is in the <BrowserRouter> and I get this...
Read more >React Router v6 in depth guide - YouTube
Welcome to react - router version 6 in-depth guide. In this video, we will learn about react - router v6 but creating a...
Read more >[Solved]-React Router failed prop 'history', is undefined-Reactjs
or BrowserHistory import { BrowserRouter as Router, Route } from 'react-router-dom'; import App from './components/App'; render(( <Router> <Route exact ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I just put up #3110, which should at least make this work without erroring:
Would something like this fix? At the top of the file import from history module
Then to declare the RouterHistory Type: