saptarshi tah
saptarshi tah

Reputation: 7

Error: Invariant failed: You should not use <withRouter(Connect(App)) /> outside a <Router>

Error: Invariant failed: You should not use <withRouter(Connect(App)) /> outside a

The above error occure when I wrap my App component with withRouter. This error while occure when I made following changes,

import {BrowserRouter,Switch,Route,withRouter} from 'react-router-dom';

export default withRouter (connect(null,mapDispatchToProps)(App));

have any solutions?

Upvotes: 0

Views: 1036

Answers (2)

Nikhil Ponduri
Nikhil Ponduri

Reputation: 531

Can you try this

import {BrowserRouter,Switch,Route,withRouter} from 'react-router-dom';

export default connect(null,mapDispatchToProps)(withRouter(App)));

Upvotes: 0

Deepak Gupta
Deepak Gupta

Reputation: 658

You can do it in separate lines

const ReduxApp = connect(null,mapDispatchToProps)(App)
export default withRouter(ReduxApp)

You won't need withRouter if you pass the props in the Routes

 <Route path="/" component={(p) => <Component {...p} {...props}/>} />

Here p is the props related to react router and props is the redux state

Upvotes: 1

Related Questions