简体   繁体   English

执行“npm start”命令后,代码为“COMPILED SUCCESSFULLY”并将我重定向到 web 浏览器。 但是没有任何 output

[英]After executing "npm start" command, the code was "COMPILED SUCCESSFULLY" and redirected me to the web browser. But there wasn't any output

App.js应用程序.js

import React, { Component } from 'react';

import Home from './Home';
import About from './About';

import './App.css';
import {Route} from "react-router-dom";

class App extends Component {
  render() {
    return (
      <div className="App">
        <Route path="/"  component={Home}/>
        <Route path="/about"  component={About}/>
      </div>
    );
  }
}

export default App;

Home.js主页.js

import React, { Component } from 'react';

class Home extends Component {
 render(){
return(
    <div>
    <h1>Home </h1>
    
    
    </div>

)


 }
  }

export default Home;

About.js关于.js

import React, { Component } from 'react';

class About extends Component {
 render(){
return(
    <div>
    <h1>About</h1>
    
    
    </div>

)


 }
  }

export default About;

package.json package.json

{
  "name": "demo-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-router-dom": "^6.0.2",
    "react-router-native": "^6.0.2",
    "react-scripts": "0.9.5"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  }
}

you need to setup an router and an switch for your routes to work.您需要设置路由器和交换机才能使路由正常工作。 docs文档

change your app.js to将您的 app.js 更改为

import React, { Component } from 'react';

import Home from './Home';
import About from './About';

import './App.css';
import { BrowserRouter as Router, Switch, Route } from 'react-router-dom';

class App extends Component {
  render() {
    return (
      <div className="App">
        <Router>
           <Switch>
               <Route path="/"  component={Home}/>
               <Route path="/about"  component={About}/>
           </Switch>
        </Router>
      </div>
    );
  }
}

export default App;

暂无
暂无

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

相关问题 npm 中的 127.0.0.1 live-server 无法在任何浏览器中打开。 这里有什么问题? - 127.0.0.1 live-server in npm can't open in any browser. what is the problem here? Webpack已成功编译但未在浏览器中显示输出 - Webpack successfully compiled but does not show output in browser 反应&#39;npm start&#39;给我错误,对于其他项目命令成功执行 - React 'npm start' giving me errors, for other projects the command executes successfully ReactJS 代码编译成功,但未在浏览器上打印 - ReactJS code compiled successfully , but not printing on Browser 成功安装 create-react-app 后 Npm 启动将无法正常工作。 错误代码 Enoent 错误编号 -4058 - Npm start won't work after successfully installing create-react-app. Error code Enoent Error number -4058 我刚刚开始构建我的 react.js 组合,但是当我使用 npm 开始时,我的浏览器中没有显示任何内容。 我创建的 header 没有显示 - I just started building my react.js portfolio but when I use npm start, nothing shows in my browser. My header ive created doesn't show npm启动成功后,localhost只显示该页面homepage.js的源码 - After npm successfully start ,localhost is only showing source code of that page homepage.js 使用Reactjs和bash命令构建后,本地主机网页为空:npm start - localhost web page is empty after building using Reactjs and bash command: npm start 无法在浏览器中调试React + Typescript。 JS文件未在输出目录中生成 - Can't debug React+Typescript in browser. JS files not generated in output directory 我的终端正在读取 webpack 编译成功,但连接到 react-dom 后浏览器页面为空 - My terminal is reading webpack compiled successfully but browser page is empty after connecting to react-dom
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM