React-router: OnEnter hook called twice

Created on 16 Dec 2016  路  5Comments  路  Source: ReactTraining/react-router

Hi all!

I'm trying to make a straightforward case work, but I'm failing to understand why onEnter hook on a router is called twice. Please see the code below:

const history = syncHistoryWithStore(browserHistory, store);

ReactDOM.render(
    <div>
        <Provider store={ store }>
        <Router history={ history }>
            <Route path="/" component={ App }>
                <IndexRedirect to="dashboard" />
                <Route path="login" component={ Login } />
                <Route path="dashboard" component={ Dashboard } onEnter={ requireAuth } />
            </Route>
        </Router>
        </Provider>
    </div>,
    document.getElementById('root')
);

I would like to have my customers redirected to /dashboard by default. If they're not signed in, they should go to /login . All good, but onEnter hook ( my requireAuth function ) is called twice. What could I have done wrong? Seems like a bug to me.

Seems obvious, but I'm using react-redux, react-router and react-router-redux.

Version

react-router 3.0.0
react-redux 4.4.6
react-router-redux 4.0.7

Test Case

I could make a jsbin if needed

Most helpful comment

I have this issue in 4.0.6 and 4.0.8

All 5 comments

Most likely a dupe of #3220

How is that a duplicate? Even if it was, I don't see an explanation or a workaround.

OK, https://github.com/reactjs/react-router-redux/issues/481 is the reason. Downgrade to react-router-redux 4.0.6 fixed the issue

I have this issue in 4.0.6 and 4.0.8

@designbyadrian Me too, both 4.0.6 and 4.0.8.

Was this page helpful?
0 / 5 - 0 ratings