How can exclude render of Layout
component when the route is /login
, /register
etc... in NextJS?
const MyApp = ({ Component, pageProps }) => {
return (
<Layout>
<Component {...pageProps} />
</Layout>
);
};
What I have done so far inside Layout.js
const router = useRouter();
if (router.pathname.includes('/login')) return children;
if (router.pathname.includes('/register')) return children;
EDIT: the above solution works, just wanted to know if nextjs routing provides a "good practice" way to solve this problem
Follow these steps to exclude a specific component from layout. This will exclude the dashboard component from the layout.
const Dashboard = ({ children }) => {
return (
<>
<DashboardContent children={''}/>
</>
);
};
export default Dashboard;
Dashboard.getLayout = function PageLayout(page) {
return (
<>
{page}
</>
)
}
export default function App({ Component, pageProps }: AppProps) {
if (Component.getLayout) {
return Component.getLayout(
<Component {...pageProps} />
)
}
return <Component {...pageProps} />
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With