简体   繁体   English

基本的 React 应用程序一直挂在 Localhost 上

[英]Basic React Application keeps hanging on Localhost

I have some error in my code, that when I launch 'npm start' on my React App, the page never loads and is continually hanging making my mac sound like it's gearing for liftoff.我的代码中有一些错误,当我在我的 React 应用程序上启动“npm start”时,页面永远不会加载并且一直挂起,这让我的 mac 听起来像是在准备起飞。 No errors in the console appear and no errors in my terminal either.控制台中没有出现错误,我的终端中也没有错误。

This is my Main.js:这是我的 Main.js:

import React, { Component } from "react";
import { BrowserRouter as Router, Switch, Route, Link } from "react-router-dom";

import NavBar from "./Navbar";
import Content from "./Content";
import Book from './Book.jsx';

import "./MainStyles.css";

export default class main extends Component {
  render() {
    return (
      <div className="wrapper">
         <Router>
        <nav className="navbar justify-content-end navbar-expand-lg sticky-top navbar-dark" style={{ backgroundColor: "#556B2F" }}>
          <a className="navbar-brand title" href="#"> Refuting Dish</a>
          <button className="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
            <span className="navbar-toggler-icon"></span>
          </button>
          <div className="collapse navbar-collapse justify-content-end" id="navbarSupportedContent">
            <ul className="navbar-nav">
              <li className="nav-item">
                <Link to="/book" className="nav-link" href="#"> Book </Link>
              </li>
            </ul>
          </div>
        </nav>
      </Router>
      <Switch>
        <Route exact path="/" component={main}/>
        <Route path="/book" component={Book}/>
      </Switch>
      <Content /> 
    </div>

This has something to do with the <Router> , or the <Switch> tags, as when I comment them out, the page loads within seconds.这与<Router><Switch>标签有关,因为当我将它们注释掉时,页面会在几秒钟内加载。

This is my browser + console:这是我的浏览器+控制台: 在此处输入图像描述

And my terminal:我的终端:

在此处输入图像描述

I suppose what I'm most frustrated about is that I have no hints, either in my console or terminal that tell me what's breaking my App.我想我最沮丧的是我没有任何提示,无论是在我的控制台还是终端中,都没有告诉我是什么破坏了我的应用程序。 If anyone can suggest a tool or extension that would catch this type of error in future cases, I would surely appreciate that.如果有人可以建议一个工具或扩展来在未来的情况下捕获此类错误,我肯定会很感激。

Thank you.谢谢你。

You Put the component Main in the same component.您将组件Main放在同一组件中。 It will load until infinite它将加载直到无限

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM