Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

276
Views
NextJs Layout Login page?

I'm covering app js with layout. I have the sidebar on the left and my pages on the right. But what I want is that the sidebar should not appear on the login page, how can I edit it?

_app.js enter image description here

Layout.js enter image description here

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

you can add a condition with pathname to showing the component or not

something like this:

const router = useRouter():

return (
   ...
   {router.pathname !== '/login' && <Sidebar path={router.route} />}
   ...
)

about 4 years ago · Juan Pablo Isaza Report

0

If you have some pages that are protected and can be seen by logged in user than you would need Public and Protected Routes and you can show in your Public routes only

If this is not the case then solution mentioned by @kaveh karami is good

about 4 years ago · Juan Pablo Isaza Report

0

I would create a HOC(Higher-Order-Component) called WithSidebar:

import Main from '../../components/Main/Main';
import Sidebar from '../../components/Sidebar/Sidebar';
import classes from './WithSidebar.module.scss';

const WithSidebar = (Component) => {

    return props => (
        <div className={classes.WithSidebar}>
            <Sidebar />
            <Main className={classes.Container}>
                <Component {...props} />
            </Main>
        </div>
    );
};

export default WithSidebar;

And then export the pages that should include the sidebar like so:


import WithSidebar from '../hoc/WithSidebar/WithSidebar';

const MyPage = () => {

    return (...)
}

export default WithSidebar(MyPage)

I find this approach really cleaner than conditionally rendering based on the pathname.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!