Next.js Discord

Discord Forum

Tell the difference between root page and not found

Unanswered
Lithuanian Hound posted this in #help-forum
Open in Discord
Avatar
Lithuanian HoundOP
I'm sure I can improve on the structure of my site as a whole, but right now in my root layout.tsx, I have the following code:
    const path = headers().get("next-url");
    let top_margin = "mt-[70px]",
        content_padding = "p-2 pt-3";
    if (!path || path === "/") {
        top_margin = "mt-[120px]";
        content_padding = "";
    }

The idea being that on my landing page, I have my header bigger, and thus want the top margin different. However, when I hit a not found page, the path shows up as null, which makes sense I guess. I'm not sure how to check if I'm at my actual root or at the not found or other simiar situations that may arrise.

0 Replies