尝试导入错误:“ BrowseRouter”未从“ react-router-dom”导出(导入为“ Router”)

时间:2020-09-10 03:08:32

标签: javascript reactjs react-router-dom react-router-v4

我不知道为什么会出现此错误,我尝试过在线搜索,但看到了一些我尝试过的建议,但错误无法清除。请问有人对做错事有任何想法吗? 这是我的代码:

import React from 'react';

import { BrowseRouter as Router, Route } from 'react-router-dom';

import Join from './components/Join';
import Chat from './components/Chat';

const App = () => (
    <Router>
        <Route path="/" exact component={Join} />
        <Route path="/chat" exact component={Chat} />
    </Router>
);

export default App;

2 个答案:

答案 0 :(得分:2)

react-router-dom不导出BrowseRouter,而是导出BrowserRouter

Documentation here

答案 1 :(得分:0)

BrowserRouter **拼写错误,您将其作为BrowseRouter。 它应该是BrowserRouter而不是BrowseRouter。 试试这个

从“ react-router-dom”导入{BrowserRouter as Router};