Skip to content

this.context.history is undefined #6

Description

@pokatomnik

index.js:

import 'babel-polyfill';
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import './index.css';
import { Router, Route, IndexRoute } from 'react-router';
import { createHashHistory  } from 'history';

const history = createHashHistory();

ReactDOM.render(
  <Router history={ history }>
    <Route path="/" component={App}>
    </Route>
  </Router>,
  document.getElementById('root')
);

App.js:

import React, { Component } from 'react';
import { Link } from 'react-router-link';
import logo from './logo.svg';
import './App.css';

class App extends Component {
  render() {
    return (
      <div className="App">
        <Link historyType="replace" to="/someplace">Click to go to someplace</Link>
      </div>
    );
  }
}

export default App;

When I click to this link an error appear in console:
index.js:111 Uncaught TypeError: Cannot read property 'replaceState' of undefined
Then I go deeper into sources:
this.context.history.replaceState(this.props.state, this.props.to, this.props.query);
This.context.history is undefined here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions