Quickly build react development environment and React-router 4.x routing configuration using Create-react-app

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.