Javascript 未捕获错误:不应使用<;开关>;a<;路由器>;,但开关在里面

Javascript 未捕获错误:不应使用<;开关>;a<;路由器>;,但开关在里面,javascript,reactjs,react-redux,react-router,react-router-v4,Javascript,Reactjs,React Redux,React Router,React Router V4,当我尝试运行我的应用程序时,开发者工具给了我这个错误 我无法理解,因为我将交换机组件放置在ConnectedOuter中。有什么想法吗 src.ca056580.js:28856 Uncaught Error: You should not use <Switch> outside a <Router> src.ca056580.js:25432 The above error occurred in one of your React components:

当我尝试运行我的应用程序时,开发者工具给了我这个错误

我无法理解,因为我将交换机组件放置在ConnectedOuter中。有什么想法吗

src.ca056580.js:28856 Uncaught Error: You should not use <Switch> outside a <Router>
    src.ca056580.js:25432 The above error occurred in one of your React components:
    in Switch (created by Routes)
    in Routes (created by AuthenticatedAppView)
    in ErrorBoundary (created by AuthenticatedAppView)
    in div (created by Tag(div))
    in Tag(div) (created by AppWidth)
    in AppWidth (created by AppContent)
    in main (created by index_AppContentLayout)
    in index_AppContentLayout (created by AppContent)
    in AppContent (created by AuthenticatedAppView)
    in div (created by Tag(div))
    in Tag(div) (created by index_AppLayout)
    in index_AppLayout (created by AuthenticatedAppView)
    in AuthenticatedAppView (created by Connect(AuthenticatedAppView))
    in Connect(AuthenticatedAppView) (created by Route)
    in Route (created by withRouter(Connect(AuthenticatedAppView)))
    in withRouter(Connect(AuthenticatedAppView)) (created by App)
    in Router (created by ConnectedRouter)
    in ConnectedRouter (created by App)
    in Provider (created by App)
    in App (created by HotExportedApp)
    in AppContainer (created by HotExportedApp)
    in HotExportedApp
    in ModalStack (created by AppRoot)
    in OverlayState (created by AppRoot)
    in div (created by AppLayerContainer)
    in AppLayerContainer (created by AppLayers)
    in div (created by AppLayerContainer)
    in AppLayerContainer (created by AppLayers)
    in AppLayers (created by AppRoot)
    in AppRoot
src.ca056580.js:28856未捕获错误:您不应该在
src.ca056580.js:25432上述错误发生在您的一个React组件中:
在交换机中(由路由创建)
路由中(由AuthenticatedAppView创建)
在ErrorBoundary中(由AuthenticatedAppView创建)
在div中(由标记(div)创建)
in标记(div)(由AppWidth创建)
在AppWidth中(由AppContent创建)
主目录中(由索引\u AppContentLayout创建)
索引中的AppContentLayout(由AppContent创建)
在AppContent中(由AuthenticatedAppView创建)
在div中(由标记(div)创建)
in标记(div)(由索引_AppLayout创建)
索引中的应用布局(由AuthenticatedAppView创建)
在AuthenticatedAppView中(由Connect(AuthenticatedAppView)创建)
在连接中(AuthenticatedAppView)(通过路由创建)
路由内(由withRouter(连接(AuthenticatedAppView))创建)
在withRouter中(连接(AuthenticatedAppView))(由应用程序创建)
路由器中(由ConnectedRouter创建)
在ConnectedRouter中(由应用程序创建)
在提供程序中(由应用程序创建)
应用内(由HotExportedApp创建)
在AppContainer中(由HotExportedApp创建)
在HotExportedApp中
在ModalStack中(由Approt创建)
在OverlyState中(由Approt创建)
在div中(由AppLayerContainer创建)
在AppLayerContainer中(由AppLayers创建)
在div中(由AppLayerContainer创建)
在AppLayerContainer中(由AppLayers创建)
在应用程序中(由Approt创建)
接近
但您可以看到ConnectRouter已经创建。下面是代码片段

AuthenticatedApp导入了路由组件,其中包含
类AuthenticatedAppView扩展组件{
componentDidMount(){
this.props.fetchCompanies()
}
render(){
返回(
)
}
}
这是路由组件,包含交换机和路由

const Routes=()=>(
} />
} />
)
导出默认路由
这是App/组件,它在路由器中包含AuthenticatedApp组件,所以交换机也应该在路由器中。我做错了什么

从“React”导入React
从“反应热加载程序”导入{hot}
从“react redux”导入{Provider}
从“react Router redux”导入{ConnectedRouter as Router}
从“历史记录/createBrowserHistory”导入createHistory
从“/configureStore”导入{configureStore}
从“./AuthenticatedApp”导入AuthenticatedApp
const history=createHistory({basename:'/'})
常量存储=配置存储(历史)
常量应用=()=>(
)
导出默认热(模块)(应用程序)

React Router Redux已被弃用,因此您的错误很可能是此弃用的结果。您应该迁移到React Router,它可以与Redux配合使用(请参阅)

您需要
npm安装react-router-dom
,以便在浏览器中使用

使用React路由器,您可以使用替换ConnectedRouter

下面是一个示例(在App.js中):

从“React”导入React;
从'react redux'导入{Provider};
从“react router dom”导入{BrowserRouter};
从“/redux store”导入{store};
从“./AuthenticatedApp”导入AuthenticatedApp
常量应用=()=>{
}

修复了它!我不得不返回以对v.4.3.1作出反应。