Week 16 - Session 2 - React (Routers)


Following on from the previous sessions;
- Intro to React
- React (Class, Stateful Components, Event Handlers)
- React (Bind Methods, Render Lifecycle)
- React (Fetching data from an external API)
- React (Forms)

React Routers: React Router is the standard routing library for React. When you need to navigate through a React application with multiple views, you’ll need a router to manage the URLs. React Router does that, keeping your application UI and the URL in sync.

Here’s an example of how our routes will look:
```js
<Router>
  <Route exact path="/" component={Home}/>
  <Route path="/category" component={Category}/>
  <Route path="/login" component={Login}/>
  <Route path="/products" component={Products}/>
</Router>

```
You need a router component and several route components to set up a basic route as exemplified above. There are two types of routers from the React Router API:

  • <BrowserRouter> - more popular because it uses the HTML5 History API to keep track of your router history.
  • <HashRouter> - uses the hash portion of the URL (window.location.hash) to remember things.
If you intend to support legacy browsers, you should stick with `<HashRouter>`.

Routing React Apps: The Complete Guide - https://scotch.io/tutorials/routing-react-apps-the-complete-guide

Popular posts from this blog

Week 9 to 12 - Learning with MCR Codes

Week 8 - Session 1 - JavaScript in the Browser

Week 9 - Session 1 - The Internet, the Web, HTTP