How To Implement Different Layouts In React

A step by step guide with an example React project

Bhargav Bachina
Bachina Labs

--

Photo by Clark Van Der Beken on Unsplash

Every web application doesn’t have the same layout for the entire pages. Some pages have header and footer, some pages have left navigation, some pages are without footer or left navigation. One way to achieve this is to hide or show based on the page you are on, but, it’s not an efficient way.

The efficient solution would be defining different layouts or templates and route the appropriate routes using React Router. In this post, We will see how we can achieve this with an example project using React Router.

  • Introduction
  • Prerequisites
  • Example Project
  • Implementation
  • Summary
  • Conclusion

Introduction

We all know the DRY principle where we should not repeat things in software development. When we define Layouts for the routes, we are actually separating a lot of common functionality from the pages such as header, footer, banner, etc. In this way, if we want to change anything in the header, all we need to change in one place.

Here are the three layouts that we are implementing in this project. The Layout1 is the layout that…

--

--