Bomber Bomber - 1 year ago 991
Javascript Question

react-router go back a page how do you configure history?

Can anyone please tell me how I can go back to previous page rather than a specific route?

When using this code:

var BackButton = React.createClass({

mixins: [Router.Navigation],
render: function() {
return (
className="button icon-left"

navigateBack: function(){

Get this error, goBack() was ignored because there is no router history

Here are my routes:

// Routing Components
Route = Router.Route;
RouteHandler = Router.RouteHandler;
DefaultRoute = Router.DefaultRoute;

var routes = (
<Route name="app" path="/" handler={OurSchoolsApp}>
<DefaultRoute name="home" handler={HomePage} />
<Route name="add-school" handler={AddSchoolPage} />
<Route name="calendar" handler={CalendarPage} />
<Route name="calendar-detail" path="calendar-detail/:id" handler={CalendarDetailPage} />
<Route name="info-detail" path="info-detail/:id" handler={InfoDetailPage} />
<Route name="info" handler={InfoPage} />
<Route name="news" handler={NewsListPage} />
<Route name="news-detail" path="news-detail/:id" handler={NewsDetailPage} />
<Route name="contacts" handler={ContactPage} />
<Route name="contact-detail" handler={ContactDetailPage} />
<Route name="settings" handler={SettingsPage} />
);, function(Handler){
var mountNode = document.getElementById('app');
React.render(<Handler /> , mountNode);

Answer Source

I think you just need to enable BrowserHistory on your router by intializing it like that : <Router history={new BrowserHistory}>.

Before that, you should require BrowserHistory from 'react-router/lib/BrowserHistory'

I hope that helps !

UPDATE : example in ES6

var BrowserHistory = require('react-router/lib/BrowserHistory').default;

var App = React.createClass({
    render: function() {
        return (

    <Router history={BrowserHistory}>
        <Route path="/" component={App} />
), document.body);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download