ccapndave / react-router-link

An updated Link component for React-router
10 stars 6 forks source link

this.context.history is undefined #6

Open pokatomnik opened 7 years ago

pokatomnik commented 7 years ago

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.

ccapndave commented 7 years ago

I'm afraid that I am currently not using React nor this component so I can't make any fixes. I'd be happy to receive PRs if anyone wants to fix this!