Opt out of Layout Component for specific pages #23628
-
I have found out this cool trick to opt out of
import "../styles/globals.css";
import Layout from "../components/Layout";
function MyApp({ Component, pageProps }) {
switch (Component.name) {
//Component which do not need to be wrapped in Layout
case "Home": //Exported function name here
return <Component {...pageProps} />;
//All other component to be wrapped inside Layout
default:
return (
<Layout>
<Component {...pageProps} />{" "}
</Layout>
);
}
}
export default MyApp; Just make sure to name your components uniquely. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hi const name = 'Supa hot fire' export default function Layout({ children, home }) { <meta property="og:image" content={ https://og-image.vercel.app/${encodeURI( siteTitle )}.png?theme=light&md=0&fontSize=75px&images=https%3A%2F%2Fassets.vercel.com%2Fimage%2Fupload%2Ffront%2Fassets%2Fdesign%2Fnextjs-black-logo.svg }/> {home ? ( <> ![]() {name}</> ) : ( <> ![]()
|
Beta Was this translation helpful? Give feedback.
-
Update: We’re excited to announce Next.js 13, which includes the new Inside the You can leave feedback here: #41745 |
Beta Was this translation helpful? Give feedback.
Update: We’re excited to announce Next.js 13, which includes the new
app/
directory (beta) with support for nested layouts, colocation of data fetching, streaming, Server Components by default, and much more.Inside the
app/
directory, there is a powerful new way to fetch data with React’suse()
hook and the extended Webfetch()
API. This allows you to colocate data fetching directly inside components for the most flexibility, including inside layouts.You can leave feedback here: #41745