Create-react-app is from Facebook, which allows us to quickly build a react development environment without configuration.
Create-react-app automatically created projects are based on Webpack + ES6
The following commands are executed:
NPM Install create-react-app-g // Global Installation Create-react-app, if you do not want to install globally, do not-G. May be slow, you can use CNPM to install create-react-app my-app // My-app is the project name CD my-app npm start // Start Project
This is the right place to go, and there's nothing to say.
The next thing to say is the React-router 4.x routing configuration.
Before is according to React-router 4.x the following version to configure, the results found that old error, dead or alive run out, on-line check data A look, pit Dad, the original 3.x and 4.x route configuration is completely different.
The 4.x version needs to be installed React-router-dom
Preparation: Installation React-router-dom
npm Install react-router-dom--save // --save will add the dependency package name to the Package.json file dependencies key, run-time dependent
(1), create the Components folder under the SRC folder to store the component. For example mine is this:
Where Index.js is the routing configuration file.
(2), in the routing configuration file index.js, import the components to be used in turn and the components that the route needs to use. As my configuration is:
Import React, {Component} from ' React '; import reactdom from ' react-dom '; import {Browserrouter as Router, Route, Link}from ' react-router-dom '; Import './index.css '; Import App from './components/app '; Importing the app component import about from './components/about '; Import about component import Inbox from './components/inbox '; Importing Inbox Components import Registerserviceworker from './registerserviceworker '; Export default class Hello extends component{R Ender () {return (<Router> <div> <ul classname= "NAV") ; <li><link to= "/" >App</Link></li> <li><link to= "/about" >About</Link>< /li> <li><link to= "/inbox" >Inbox</Link></li> </ul> Where exact is used to "/" do the only match. If this is not the case, it will match the other matches to the current
The results are as follows:
Quickly build react development environment and React-router 4.x routing configuration using Create-react-app