React Router Dom挂起浏览器

时间:2019-04-13 00:35:23

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

我正在尝试按照课程学习,当我安装<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/> <div id="tiene_circulos"> <div class="circulo_iconos" data-number="1"> <span class="fa fa-fw fa-star"></span> </div> <div class="circulo_iconos" data-number="2"> <span class="fa fa-fw fa-star"></span> <span class="fa fa-fw fa-star"></span> </div> <div class="circulo_iconos" data-number="3"> <span class="fa fa-fw fa-star"></span> <span class="fa fa-fw fa-star"></span> <span class="fa fa-fw fa-star"></span> </div> <div class="circulo_iconos" data-number="4"> <span class="fa fa-fw fa-star"></span> <span class="fa fa-fw fa-star"></span> <br /> <span class="fa fa-fw fa-star"></span> <span class="fa fa-fw fa-star"></span> </div> <div class="circulo_iconos" data-number="5"> <span class="fa fa-fw fa-star"></span> <span class="fa fa-fw fa-star"></span> <span class="fa fa-fw fa-star"></span> <span class="fa fa-fw fa-star"></span> <span class="fa fa-fw fa-star"></span> </div> <div class="circulo_iconos" data-number="6"> <span class="fa fa-fw fa-star"></span> <span class="fa fa-fw fa-star"></span> <span class="fa fa-fw fa-star"></span> <span class="fa fa-fw fa-star"></span> <span class="fa fa-fw fa-star"></span> <span class="fa fa-fw fa-star"></span> </div> </div>并运行react-router-dom时,浏览器中断了

这是我的npm start

package.json

在我的"dependencies": { "react": "16.8.3", "react-dom": "16.8.3", "react-router-dom": "4.3.1", "react-scripts": "2.1.5" }, "eslintConfig": { "extends": "react-app" }, "browserslist": [ ">0.2%", "not dead", "not ie <= 11", "not op_mini all" ] } 中:

index.js

在我的 import React from 'react'; import App from './components/App'; import 'bootstrap/dist/css/bootstrap.css'; import './global.css'; const container = document.getElementById('app'); ReactDOM.render(<App/>, container);

App.js:

我做错什么了吗?

1 个答案:

答案 0 :(得分:1)

我遇到了同样的问题。

快速疑难解答-

  1. 确保徽章 BadgeNew 组件没有“交换路由”定义或与此相关的任何内容。
  2. 将所有路线定义保留在App js文件中
  3. 使用index.js文件中的BrowserRouter来包装。将其从App.js中取出