react-router: react-router-config - You should not use outside a (it is inside a Router!)

Version

5.0.0

Steps to reproduce

Use react-router-config with a static routes map

Expected Behaviour

It should work the same as in version 4.3.0

Actual Behaviour

Uncaught Error: Invariant failed: You should not use <Switch> outside a <Router>

    in Switch
    in Router (created by MyRoutes)
    in Provider (created by MyRoutes)
    in MyRoutes```

Note from the component stack that my Switch is most definitely inside a Router.

I'm not sure if this issue may be specific to my use of `react-router-config` package, or that I'm wrapping the router in a redux Provider.

Also note that I have verified that no old instances of react-router 4.x are lingering around in my node_modules (I saw another issue suggesting that this might be causing this issue).

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 18 (3 by maintainers)

Commits related to this issue

Most upvoted comments

I had the same issue. This worked in v4.x but surprisingly broke in v5. My fix was to make sure that I imported everything from react-router-dom. Previously, I mixed between react-router and react-router-dom. According to this comment react-router-dom re-exports stuff from react-router. I think this deserves to be looked at more.

The same issue when using StaticRouter in SSR

Btw, if someone else stumbles upon this very same strange issue, I got tired of searching for a solution. I downgraded both react-router and react-router-dom to version 4.3.1 and now it works like a charm.

Don’t bother losing time on this, and try again in a few months… or years.

Use connected-react-route

and

"react-router": "^4.3.1" "react-router-dom": "^4.3.1"

I was using react-router-redux which is deprecated. Switching to connected-react-router resolved this problem for me.

I am getting the same issue was working fine on react router 4 , upgraded and it broke , however i only get this error when i build the app using webpack production mode : ( ,