JSX 元素类型“Route”没有任何构造或调用签名 - 路由问题
2020-06-12
465
我遇到了 Route 错误“消息”:“JSX 元素类型‘Route’没有任何构造或调用签名。”
在浏览器中: ./src/app/layout/App.tsx 尝试导入错误:“react-router-dom”不包含默认导出(导入为“Route”)。
我真的不知道哪里出了问题。
import React from "react";
import NavBar from "../../features/nav/NavBar";
import Footer from "../../features/footer/Footer";
import Route, { BrowserRouter } from "react-router-dom";
import Dashboard from "../../features/dashboard/Dashboard";
import TestApiDashboard from "../../features/testApiDashboard/TestApiDashboard";
const App = () => {
return (
<div>
<div className="main">
<NavBar />
<Route path="/" component={Dashboard} />
<Route path="/testApiDashboard" component={TestApiDashboard} />
<Route path="/" component={Dashboard} />
</div>
<Footer />
</div>
);
};
export default App;
index.tsx
import React from 'react';
import ReactDOM from 'react-dom';
import {BrowserRouter} from 'react-router-dom';
import './app/layout/styles.css';
import App from './app/layout/App';
import * as serviceWorker from './serviceWorker';
ReactDOM.render(
<React.StrictMode>
<BrowserRouter>
<App />
</BrowserRouter>
</React.StrictMode>,
document.getElementById('root')
);
serviceWorker.unregister();
1个回答
您需要以不同的方式导入以下内容:
import {
BrowserRouter,
Route,
} from "react-router-dom";
而不是您的代码片段:
import Route, { BrowserRouter } from "react-router-dom";
您可以在
<Route />
中进一步阅读。希望这对您有所帮助!
norbitrial
2020-06-12