BrowserRouter v4 - 'BrowserRouter'未定义react / jsx-no-undef

时间:2017-10-16 17:50:09

标签: javascript node.js reactjs

我想在我的反应应用中使用BrowserRouter。我在BrowserRouter标签中嵌套了我最顶层的组件,如下所示:

import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter as Router, Route, Link } from 'react-router-dom';
import App from './App';
import registerServiceWorker from './registerServiceWorker';


ReactDOM.render((
    <BrowserRouter>
        <App/>
    </BrowserRouter>
), document.getElementById('root')); 

registerServiceWorker();

我收到以下错误:

./src/index.js
Line 9:  'BrowserRouter' is not defined  react/jsx-no-undef

我已经安装了react-router-dom,并且依赖性在我的package.json文件中。那我为什么要这个呢?

1 个答案:

答案 0 :(得分:7)

您将其导入为Router,因此您也应将其称为<Router>