Adding a home route to MainRouter

The MainRouter.js code will help render our custom React components with respect to routes or locations in the application. In this first version, we will only add the root route to render the Home component.

mern-skeleton/client/MainRouter.js:

import React, {Component} from 'react'import {Route, Switch} from 'react-router-dom'import Home from './core/Home'class MainRouter extends Component {  render() {    return (<div>      <Switch>        <Route exact path="/" component={Home}/>      </Switch>    </div>)  }}export default MainRouter

As we develop more view components, we will update the MainRouter to add routes for the new components inside the Switch component.

The Switch component in React Router renders a route exclusively. ...

Get Full-Stack React Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.