4
votes

I want to add react-route to my app, i have the code below:

import React from 'react'; import ReactDOM from 'react-dom';

import { Router, browserHistory } from 'react-router';

import App from './App.js';

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

app:

import React from 'react';

class App extends React.Component {
    render() {
        return (
            <div className="container">
                Hello
            </div>
        );
    }
}

export default App;

I have a spring boot server which listens on 8080, in browser i get error when checking localhost:8080 (debug mozilla):

ReferenceError: Route is not defined

I have "react-router": "^4.1.1".

EDIT: imported route but i get now:

TypeError: i.props.history is undefined

UPDATE: Installed react-router 3.0.2 and worked.

2

2 Answers

6
votes

Just import Route from react-router

import { browserHistory, Router, Route } from 'react-router';

0
votes

You need to use BrowserRouter or HashRouter from react-router-dom package, not Router from react-router package, if you are using react router in a webbrowser.

You should never need to import react-router yourself, react-router-dom will do this for you.