Skip to content

Instantly share code, notes, and snippets.

@ManotLuijiu
Created January 31, 2021 12:27
Show Gist options
  • Save ManotLuijiu/4f8a590a4411d568e6fad60ca9a07e60 to your computer and use it in GitHub Desktop.
Save ManotLuijiu/4f8a590a4411d568e6fad60ca9a07e60 to your computer and use it in GitHub Desktop.
In case, you need to hide some component in react.js or next.js
import React from 'react';
import { useRouter } from 'next/router';
import Nav from './Nav';
import Header from './Header';
import Footer from './Footer';
const Layout = ({ children }) => {
const router = useRouter();
const { pathname } = router;
const noHeader = ['/login', '/register'];
return (
<div>
<Nav />
<div className="flex flex-col h-screen">
{noHeader.includes(pathname) ? null : <Header />}
<main className="mb-auto">{children}</main>
<Footer />
</div>
</div>
);
};
export default Layout;
@Obaitan
Copy link

Obaitan commented Feb 18, 2023

This is gold!
Thank you.

@Wafffa
Copy link

Wafffa commented Mar 19, 2023

Thank you very much, you really helped me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment