针对您遇到的 export 'switch' (imported as 'switch') was not found in 'react-router-dom' 错误,这里有几个可能的解决步骤和原因分析: 1. 确认 'react-router-dom' 版本 首先,需要确认您项目中使用的 react-router-dom 的版本。因为从 react-router-dom 版本6 开始,Switch 组件已经被重命名为 Routes,并...
react报错export ‘Switch‘ (imported as ‘Switch‘) was not found in ‘react-router-dom‘ 报如下错,查react-router-dom版本。 因为:react-router-dom从V5升级到V6造成的 (1) 将Switch 重命名为 Routes (2) Route 的新特性变更 ,component/render被element替代 (3)嵌套路由变得更简单...
export 'withRouter' (imported as 'withRouter') was not found in 'react-router-dom' 原因:这些报错原因均为'Switch' 和'Redirect' 是react-router 5版本的接口,而最新版本是 "react-router-dom": "^6.2.1",并且已经将Switch改为Routes。 解决办法有二: 1.将所有 Switch 改为 Routes,Redirect 改为 Navi...
1. 使用 <Routes> 而不是 <Switch> 修复“‘Switch’ is not exported from ‘react-router-dom'” 错误的一种方法是将<Switch>替换为<Routes>。 让我们来看一个示例,看看如何将路由代码从 React Router 版本 5 中已废弃的<Switch>组件更新为 React Router 版本 6 中的新<Routes>组件。 在React Router ...
exact path={'/'} component={InfoShow} /> </ErrorBoundary> </Switch> </HomePage> <CompanyHome> <Switch> <ErrorBoundary> <Route path={ '/companyHome/companyBaseInfo'} component={CompanyBaseInfo} /> </ErrorBoundary> </Switch> </CompanyHome> <Route component={NotFound} /> </Switch> ...
exact path={'/'} component={InfoShow} /> </ErrorBoundary> </Switch> </HomePage> <CompanyHome> <Switch> <ErrorBoundary> <Route path={ '/companyHome/companyBaseInfo'} component={CompanyBaseInfo} /> </ErrorBoundary> </Switch> </CompanyHome> <Route component={NotFound} /> </Switch> ...
export 'Switch' (imported as 'Switch') was not found in 'react-router-dom' 使用react-router时报错! 解决方案: 将react-router版本降到5即可
What version of React Router are you using? 6.2.2 Steps to Reproduce import {BrowserRouter as Router, Switch, Route, Link} from "react-router-dom"; but the browser throwing an err says export 'Switch' (imported as 'Switch') was not found in 'react-router-dom' ...
export 'Switch' (imported as 'Switch') was not found in 'react-router-dom' (possible exports: BrowserRouter, HashRouter, Link, MemoryRouter, NavLink, Navigate, Outlet, Route, Router, Routes, UNSAFE_LocationContext, UNSAFE_NavigationContext, UNSAFE_RouteContext, createRoutesFromChildren, createSearc...
<Switch> <Route path="/users" component={MyComponent} /> <Route path="/404" component={GenericNotFound} /> <Redirect to="/404" /> </Switch> 第一种方案在实践过程中发现,首页也匹配了404,其他页面正常;第二种方案中,所有页面都会重定向到404页面个人路由设置: <BrowserRouter> <Switch> <Scroll...