====== Route ====== This is what make a single page app do not refresh. ===== Quick Start ===== It is a big topic, and here I want to make it as quick as possible to read. - Install ''react-router'', ''react-router-dom'' to your project by npm install --save react-router react-router-dom - ''import {BrowserRouter} from "react-router-dom";'' in your App.js - Wrap your application whole App inside
...
- ''import {NavLink, Route, Link, Switch} from "react-router-dom";'' or any combination of those in your container component. - Can create the or to the container class like: - To display the components based on the URL route, you can do: ===== Link, NavLink ===== If we do a xxx for a link, the page will refresh, so we need to use ''xxx'' or ''xxx'' to replace it. Details here: https://reactrouter.com/web/api/Link https://reactrouter.com/web/api/NavLink They have the following main props: * to * The URL to go to * exact * Will use this route only if the URL match exactly as the one in ''to'' * activeClassName * The class name add to this block if it is active, mostly of CSS make up Example: Go to exact path / if this Home link is click, and if it is active, it should have a css class named **my-active** ...
  • Home
  • ...
    ===== Route ===== If the url route is match to the path props, show the component, or render the JSX. Note that any URL match the path will be loaded.
    Demo1
    }/> Demo2
    ===== Switch ===== If you only need the very first route to be load on match. You can use Switch.
    Demo1
    }/>
    ===== Additional ===== * export default withRouter(COMP_NAME) * Route information on ''this.props'' * route lazy loading