question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

{history} undefined

See original GitHub issue

I 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 prophistorysupplied toRouter, expected instance ofHistory. 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:closed
  • Created 8 years ago
  • Comments:42 (10 by maintainers)

github_iconTop GitHub Comments

6reactions
gaearoncommented, Sep 7, 2015

@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:

import { createHistory } from 'history'; // you need to install this package
let history = createHistory();
2reactions
fwoncommented, Jan 24, 2016

Please update the readme file!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found