Skip to Content
Full-Stack React Projects - Second Edition
book

Full-Stack React Projects - Second Edition

by Shama Hoque
April 2020
Intermediate to advanced
716 pages
18h 55m
English
Packt Publishing
Content preview from Full-Stack React Projects - Second Edition

Adding a home route to MainRouter

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

mern-skeleton/client/MainRouter.js:

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

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

The Switch component in React Router renders a route exclusively. In other words, it only ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Full-Stack React Projects

Full-Stack React Projects

Shama Hoque
React Native - The Practical Guide

React Native - The Practical Guide

Academind by Maximilian Schwarzmüller GmbH

Publisher Resources

ISBN: 9781839215414Supplemental Content