【发布时间】:2020-11-17 07:20:29
【问题描述】:
我不知道为什么我会收到这个错误,而且我在任何地方都找不到答案。我已经卸载了react-router-dom 包并重新安装了它,但它继续告诉我switch 模块不是从react-router-dom 导出的。这是我的代码。
我遇到的错误:尝试导入错误:“Switch”未从“react-router-dom”导出。
import React from 'react';
import './App.css';
import NavBar from './components/navbar.js';
import Footer from './components/footer.js';
import Home from './components/pages/homepage/home.js';
import { BrowserRouter as Router, Switch, Route, Link } from 'react-router-dom';
function App() {
return (
<Router>
<div className="app-container">
<NavBar />
<Switch>
<Route path="/home" component={Home} />
</Switch>
<Footer />
</div>
</Router>
);
}
export default App;
`
【问题讨论】:
-
可能是来自服务工作者的缓存问题。尝试 ctrl+f5 或以隐身模式浏览
-
你得到这个问题的解决方案了吗
标签: reactjs