SlideShare a Scribd company logo
How to implement multiple layouts using React router V4.pptx
How to implement multiple layouts using React
router V4?
There may have multiple layouts when working on massive projects
while developing a project. We are frequently forced to divide our
programs into pieces, each program with its unique layout. There are
numerous occasions when multiple layouts are required for a website.
What is React Router?
React Router is a standard routing library for React.
The most basic example is when we need to separate the
administration and client parts of a website, or when we need to
change the page layout significantly for an unauthorized user.
Moreover, you can hire React developers who specialized in operating
and solving complex problems in React.
In this article, We’ll show how to use multiple layouts in a React
application without utilizing redundant mountings with React Router
v4.
Checkout This Also: React Hooks Best Practices in 2022
Installing React Router Dom:
npm install --save react-router-dom
Initial setup:
import React from "react";
import ReactDOM from "react-dom";
import { BrowserRouter } from "react-router-dom";
import Router from "components/router";
const MyApp = props => (
<BrowserRouter>
<Router />
</BrowserRouter>
);
ReactDOM.render(<MyApp />, document.getElementById("app"));
Example:
Step 1:
To introduce multiple layouts or master pages to React, we’ll first
construct two distinct layout files and their respective routes.
LoginPage.js:
We’ve constructed a custom component to serve as our first master
page or layout, as well as the route for the “LoginPageRoute” layout.
For any child components that use this layout, a child component will
be rendered at children, with the rest of the elements remaining the
same.
DashboardLayout.js:
import React, { Component } from 'react';
import { Route } from 'react-router-dom';
const DashboardLayout = ({children, ...rest}) => {
return (
<div className="page page-dashboard">
<div className="main">{children}</div>
</div>
)
}
const DashboardLayoutRoute = ({component: Component, ...rest}) => {
return (
<Route {...rest} render={matchProps => (
<DashboardLayout>
<Component {...matchProps} />
</DashboardLayout>
)} />
)
};
export default DashboardLayout;
We’ve made a custom component that will serve as our second master
page or layout, as well as a route for the layout “DashboardLayout.”
In this example, the element below will be the same for all Dashboard
Layout child components.
Step 2:
In the next stage, we’ll make two components for each layout. The first
layout will be used for our first component, while the second layout will
be used for the second component.
LoginPageForm.js:
import React, { Component } from 'react';
const LoginPageForm = ({ classes }) => {
return (
<div className="col-md-6 col-md-offset-3">
<h2>Login</h2>
<form name="form">
<div className="form-group" >
<label>Username</label>
<input type="text" className="form-control" />
</div>
<div className="form-group" >
<label>Password</label>
<input type="password" className="form-control" />
</div>
<div className="form-group">
<button type="submit" className="btn btn-primary">Login</button>
</div>
</form>
</div>
);
};
export default LoginPageForm
UserPage.js:
import React, { Component } from 'react';
const UserPage = ({ classes }) => {
return (
<div>
<h2>Welcome User</h2>
</div>
);
};
export default UserPage
Output:
Layout 1
Layout 2
Conclusion:
As you can see, altering the route renders various master pages for
distinct DOM components. With React Router v4, we simply wrap our
layout component around the routes to leverage different layouts.
Thank for Reading. Hope you enjoyed our article.
Hire top-notch React experts from Bosc Tech for React development
requirements.

More Related Content

PPTX
React JS Lecture 10.pptx Our clg lecture
PPTX
How to navigate programmatically using react router
PDF
Learn more about React Router & it's properties
PDF
Simple React Todo List
PPTX
Lecture 2 Styling and Layout in React Native.pptx
PDF
React Router: React Meetup XXL
PDF
Getting Started with React
PDF
Getting Started with React-Nathan Smith
React JS Lecture 10.pptx Our clg lecture
How to navigate programmatically using react router
Learn more about React Router & it's properties
Simple React Todo List
Lecture 2 Styling and Layout in React Native.pptx
React Router: React Meetup XXL
Getting Started with React
Getting Started with React-Nathan Smith

Similar to How to implement multiple layouts using React router V4.pptx (12)

PDF
Introduction to ReactJS and Redux
PPTX
React JS CONCEPT AND DETAILED EXPLANATION
PDF
Learn reactjs, how to code with example and general understanding thinkwik
PDF
React Router Dom Integration Tutorial for Developers
PDF
Materi Modern React Redux Power Point.pdf
PDF
2- Components.pdf
PDF
Universal JS Web Applications with React - Web Summer Camp 2017, Rovinj (Work...
PDF
Introduction to React Native & Redux
PPTX
Modern web app with REACT
PDF
Introduction to React & Redux
PPTX
ReactJs presentation
PPTX
Mastering React: Building Modern and Interactive User Interfaces
Introduction to ReactJS and Redux
React JS CONCEPT AND DETAILED EXPLANATION
Learn reactjs, how to code with example and general understanding thinkwik
React Router Dom Integration Tutorial for Developers
Materi Modern React Redux Power Point.pdf
2- Components.pdf
Universal JS Web Applications with React - Web Summer Camp 2017, Rovinj (Work...
Introduction to React Native & Redux
Modern web app with REACT
Introduction to React & Redux
ReactJs presentation
Mastering React: Building Modern and Interactive User Interfaces
Ad

More from BOSC Tech Labs (20)

PDF
How Computer Vision Powers AI-Driven Process Optimization in Manufacturing.pdf
PDF
Top 10 Ways Computer Vision is Shaping Manufacturing Process.pdf
PDF
Top Computer Vision Opportunities and Challenges for 2024.pdf
PDF
How Computer Vision Is Changing the Entertainment Industry.pdf
PDF
How can Computer Vision help Manufacturers_.pdf
PDF
Machine Learning_ Advanced Computer Vision and Generative AI Techniques.pdf
PDF
What is Generative AI_ Unpacking the Buzz Around Generative AI Development Co...
PDF
20 Unexplored Use Cases for Generative AI in Customer Service.pdf
PDF
The Role of APIs in Custom Software Development for 2024
PDF
What is Generative AI for Manufacturing Operations_.pdf
PDF
How Gen AI Is Transforming The Customer Service Experience_.pdf
PDF
Transforming Visions into Reality with Generative AI.pdf
PDF
What is ChatGPT, DALL-E, and Generative AI_.pdf
PDF
All You Need To Know About Custom Software Development
PDF
The Most Impactful Custom Software Technologies of 2024
PDF
How Vision AI and Gen AI Can Drive Business Growth_.pdf
PDF
10 Detailed Artificial Intelligence Case Studies 2024 | BOSC TECH
PDF
Computer Vision in 2024 _ All The Things You Need To Know.pdf
PDF
GoRouter_ The Key to Next-Level Routing in Flutter Development.pdf
PDF
5 Key Steps to Successfully Hire Reactjs App Developers.pdf
How Computer Vision Powers AI-Driven Process Optimization in Manufacturing.pdf
Top 10 Ways Computer Vision is Shaping Manufacturing Process.pdf
Top Computer Vision Opportunities and Challenges for 2024.pdf
How Computer Vision Is Changing the Entertainment Industry.pdf
How can Computer Vision help Manufacturers_.pdf
Machine Learning_ Advanced Computer Vision and Generative AI Techniques.pdf
What is Generative AI_ Unpacking the Buzz Around Generative AI Development Co...
20 Unexplored Use Cases for Generative AI in Customer Service.pdf
The Role of APIs in Custom Software Development for 2024
What is Generative AI for Manufacturing Operations_.pdf
How Gen AI Is Transforming The Customer Service Experience_.pdf
Transforming Visions into Reality with Generative AI.pdf
What is ChatGPT, DALL-E, and Generative AI_.pdf
All You Need To Know About Custom Software Development
The Most Impactful Custom Software Technologies of 2024
How Vision AI and Gen AI Can Drive Business Growth_.pdf
10 Detailed Artificial Intelligence Case Studies 2024 | BOSC TECH
Computer Vision in 2024 _ All The Things You Need To Know.pdf
GoRouter_ The Key to Next-Level Routing in Flutter Development.pdf
5 Key Steps to Successfully Hire Reactjs App Developers.pdf
Ad

Recently uploaded (20)

PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPT
Introduction Database Management System for Course Database
PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
Transform Your Business with a Software ERP System
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PPTX
Reimagine Home Health with the Power of Agentic AI​
PPTX
Introduction to Artificial Intelligence
PDF
System and Network Administration Chapter 2
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PPTX
history of c programming in notes for students .pptx
PDF
Digital Systems & Binary Numbers (comprehensive )
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
System and Network Administraation Chapter 3
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PPTX
L1 - Introduction to python Backend.pptx
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
Designing Intelligence for the Shop Floor.pdf
PDF
medical staffing services at VALiNTRY
How to Migrate SBCGlobal Email to Yahoo Easily
Introduction Database Management System for Course Database
PTS Company Brochure 2025 (1).pdf.......
Transform Your Business with a Software ERP System
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Reimagine Home Health with the Power of Agentic AI​
Introduction to Artificial Intelligence
System and Network Administration Chapter 2
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
history of c programming in notes for students .pptx
Digital Systems & Binary Numbers (comprehensive )
Softaken Excel to vCard Converter Software.pdf
System and Network Administraation Chapter 3
Wondershare Filmora 15 Crack With Activation Key [2025
Upgrade and Innovation Strategies for SAP ERP Customers
L1 - Introduction to python Backend.pptx
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Designing Intelligence for the Shop Floor.pdf
medical staffing services at VALiNTRY

How to implement multiple layouts using React router V4.pptx

  • 2. How to implement multiple layouts using React router V4? There may have multiple layouts when working on massive projects while developing a project. We are frequently forced to divide our programs into pieces, each program with its unique layout. There are numerous occasions when multiple layouts are required for a website.
  • 3. What is React Router? React Router is a standard routing library for React. The most basic example is when we need to separate the administration and client parts of a website, or when we need to change the page layout significantly for an unauthorized user. Moreover, you can hire React developers who specialized in operating and solving complex problems in React. In this article, We’ll show how to use multiple layouts in a React application without utilizing redundant mountings with React Router v4. Checkout This Also: React Hooks Best Practices in 2022
  • 4. Installing React Router Dom: npm install --save react-router-dom Initial setup: import React from "react"; import ReactDOM from "react-dom"; import { BrowserRouter } from "react-router-dom"; import Router from "components/router"; const MyApp = props => ( <BrowserRouter> <Router /> </BrowserRouter> ); ReactDOM.render(<MyApp />, document.getElementById("app"));
  • 5. Example: Step 1: To introduce multiple layouts or master pages to React, we’ll first construct two distinct layout files and their respective routes. LoginPage.js: We’ve constructed a custom component to serve as our first master page or layout, as well as the route for the “LoginPageRoute” layout. For any child components that use this layout, a child component will be rendered at children, with the rest of the elements remaining the same.
  • 6. DashboardLayout.js: import React, { Component } from 'react'; import { Route } from 'react-router-dom'; const DashboardLayout = ({children, ...rest}) => { return ( <div className="page page-dashboard"> <div className="main">{children}</div> </div> ) } const DashboardLayoutRoute = ({component: Component, ...rest}) => { return ( <Route {...rest} render={matchProps => ( <DashboardLayout> <Component {...matchProps} /> </DashboardLayout> )} /> ) }; export default DashboardLayout;
  • 7. We’ve made a custom component that will serve as our second master page or layout, as well as a route for the layout “DashboardLayout.” In this example, the element below will be the same for all Dashboard Layout child components. Step 2: In the next stage, we’ll make two components for each layout. The first layout will be used for our first component, while the second layout will be used for the second component.
  • 8. LoginPageForm.js: import React, { Component } from 'react'; const LoginPageForm = ({ classes }) => { return ( <div className="col-md-6 col-md-offset-3"> <h2>Login</h2> <form name="form"> <div className="form-group" > <label>Username</label> <input type="text" className="form-control" /> </div> <div className="form-group" > <label>Password</label> <input type="password" className="form-control" /> </div> <div className="form-group"> <button type="submit" className="btn btn-primary">Login</button> </div> </form> </div> ); }; export default LoginPageForm
  • 9. UserPage.js: import React, { Component } from 'react'; const UserPage = ({ classes }) => { return ( <div> <h2>Welcome User</h2> </div> ); }; export default UserPage
  • 11. Conclusion: As you can see, altering the route renders various master pages for distinct DOM components. With React Router v4, we simply wrap our layout component around the routes to leverage different layouts. Thank for Reading. Hope you enjoyed our article. Hire top-notch React experts from Bosc Tech for React development requirements.