针对您遇到的 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)嵌套路由变得更简单...
解决方案: 将react-router版本降到5即可
跟着网上做项目的时候,安装react-router-dom,配置路由时候引入Switch, 报错 import{BrowserRouterasRouter,Route,Switch}from'react-router-dom'; 1. 原因:安装了6.x版本的react-router-dom,在新版本的代码中,已经将 Switch改为Routes...
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。 解决办法有二: ...
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...
将react-router-dom 版本降级到 5 或以下 1. 使用 <Routes> 而不是 <Switch> 修复“‘Switch’ is not exported from ‘react-router-dom'” 错误的一种方法是将<Switch>替换为<Routes>。 让我们来看一个示例,看看如何将路由代码从 React Router 版本 5 中已废弃的<Switch>组件更新为 React Router 版本 ...
import { Switch, Route } from "react-router-dom";改为:import { Routes ,Route } from 'react-router-dom';之前:<Route path="/" component={Home} /> 改为:<Route path='/' element={<Home/>} /> 其他:移除 exact 此后不需要在路由中进行声明!更多修改请访问官方文档 https:...
我只好顺着错误去看看react-router-config的源码,这里发现react-router-config使用的竟然还是react-router v5的Switch,我当时就无语了,哥们时代变了你不知道吗,我的react-router-dom是^6,所以才产生了报错。 把router版本改成v5即可 不了解v6的小伙伴可以自行查阅下官网React Router | Docs Home...