I'm trying to achieve navbar and sidebar on all admin pages but not on shop. The only problem here is the shop since I put my sidebar and navbar globally. I want to make it global for only admin and not for shop.
This is my _app.js
function MyApp({ Component, pageProps }) {
return (
<>
<Layout>
<Component {...pageProps} />
</Layout>
</>
);
}
And this is my Layout File...
<>
<MenuBar onToggleMenu={toggleMenu} onToggleMenuCart={toggleMenuCart} />
<div className="ui attached pushable" style={{ height: '100vh' }}>
<Sidebar toggleMenu={toggle} />
<AddtoCartSidebar toggleMenu={toggleCart} />
<div className={classes}>
<div className="mh-25 mv-20 wrap minheight">
<div
className="content-area"
style={{ width: toggle ? '80%' : '100%' }}
>
{children}
</div>
</div>
</div>
</div>
</>
I know I can just add Navbar and Sidebar on all pages one by one but it's not a good way for me. BTW I'm using next incase you guys get confused. I have 1 folder for admin and 1 for shop. The Layout folder consists of navbar and sidebar. I'm new on next since I just started 3 days ago so I don't know that much.
EDIT: I found 1 question a bit related to mine but different in a way: Next js parent route component for children components
If you don't understand try reading his question so you'll understand mine a bit more. I'm not that good at explaining.
FOR THOSE WHO HAVE THIS PROBLEM, I figured out an answer...
If you want your page to have sidebar and navbar and if you want your other page to have no sidebar and navbar this is how you do it... If you have more shorter and better answer you guys can answer aswell :)
function MyApp({ Component, pageProps, router }) {
if (router.pathname.startsWith('/admin')) {
return (
<>
<Head>
<title>DailyMart Admin</title>
</Head>
<Layout>
<Component {...pageProps} />
</Layout>
</>
);
}
return (
<>
<Head>
<title>DailyMart Shop</title>
</Head>
<Component {...pageProps} />
</>
);
}
As you can see here i did a conditional for only my admin to see sidebar and navbar and for my shop it will have its own navbar! Cheers!
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