{history} undefined
See original GitHub issueI am trying to follow the examples from 1.0.0-beta2 or even the readme.md from master. If I do (in browser)
import {history} from 'react-router/lib/BrowserHistory';
React.render((
<Router history={history}>
...
I get Uncaught Error: Invariant Violation: Server-side <Router>s need location, branch, params, and components props. Try using Router.run to get all the props you need
Turns out that history
is undefined this way.
Even when I do
import BrowserHistory from 'react-router/lib/BrowserHistory';
React.render((
<Router history={BrowserHistory}>
...
as other examples suggest, it doesn’t work. I get
Warning: Failed propType: Invalid prop
historysupplied to
Router, expected instance of
History. Uncaught Error: Invariant Violation: A <Router> needs a valid Location
The only way I got it to work was with <Router history={new BrowserHistory()}>
but this is definitely not in the examples.
Am I doing something wrong or are the docs outdated?
Issue Analytics
- State:
- Created 8 years ago
- Comments:42 (10 by maintainers)
Top Results From Across the Web
javascript - React router - undefined history - Stack Overflow
As of "react-router": "^4.1.1", you may try the following: Use 'this.props.history.push('/new-route')'. Here's a detailed example.
Read more >React router v5 - TypeError history is undefined
Unfortunately, I was receiving TypeError: history is undefined every button was pressed. It took me a while, but the fix was trivial.
Read more >React Router, why useLocation and useHistory might return ...
const history = useHistory() const location = useLocation(). They both returned undefined . Turns out I was adding the Router to the DOM...
Read more >cannot read properties of undefined (reading 'push') history
But when I enter the keyword it says undefined. Here is my Search.js, I think there is a problem with history.push() function because...
Read more >React Functional Component UseHistory Undefined Error Fix
This is a basic fix for an issue with React useHistory that I thought wasn't immediately obvious what the problem was.
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 Free
Top 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
@knowbody
It’s gone in 1.0.0-beta4.
Now you get hash history by default (no need to specify it). If you want the pushstate history, do this:
Please update the readme file!