Render Issue
Answered
Greek Harehound posted this in #help-forum
Greek HarehoundOP
import { createServerComponentClient } from "@supabase/auth-helpers-nextjs";
import { ReactNode } from "react";
import { Toaster } from "@/components/ui/toaster";
import { cookies } from "next/headers";
import { redirect } from "next/navigation";
import Navbar from "@/components/dashboard/layouts/Navbar";
import { headers as Headers } from "next/dist/client/components/headers";
export default async function Layout({ children }: { children: ReactNode }) {
const supabase = createServerComponentClient({ cookies });
const {
data: { session },
} = await supabase.auth.getSession();
const headers = Headers();
const pathName = headers.get("x-url") || "";
const notProtected = ["/dashboard/login"];
if (!session && !notProtected.includes(pathName))
return redirect("/dashboard/login");
return (
<>
<main>
{!notProtected.includes(pathName) && <Navbar user={session.user} />}
{children}
<Toaster />
</main>
</>
);
}This my layout.tsx under /dashboard directory and i have a login page in /dashboard/login. when people login it redirects to /dashboard. But navbar doesn't render. I don't want to include navbar on login page.
Answered by Ray
Hi, you could use route group for this
app/(navbar)/layout.tsx <-- render <Navbar / here28 Replies
Hi, you could use route group for this
app/(navbar)/layout.tsx <-- render <Navbar / hereAnswer
and move the page you want to show navbar in the group
Greek HarehoundOP
Let me try
@Ray Hi, you could use route group for this
`app/(navbar)/layout.tsx` <-- render `<Navbar /` here
Greek HarehoundOP
Can I create directory like (dashboard) and dashboard at the same time?
sure
Greek HarehoundOP
Absolute lifesaver
Thank you bro
â¤ï¸
But there is a one problem
When user login i redirect user to /dashboard, but page doesn't render
There is only background
did you render
children in app/(dashboard)/layout.tsx?Greek HarehoundOP
Yes
i copy pasted the layout.tsx i sent
could you show a screenshot of the folder structure now
Greek HarehoundOP
ah
@Greek Harehound Can I create directory like (dashboard) and dashboard at the same time?
I thought you said the route group name
we can't have the same route name
Greek HarehoundOP
what should i do ?
My login page should be under the dashboard route
app/dashboard/(navbar)/layout.tsxapp/dashboard/(navbar)/articales/page.tsxapp/dashboard/login.tsxif the other page need to render navbar
app/(navbar)/layout.tsxapp/(navbar)/blogGreek HarehoundOP
No this navbar is only special for dashboard
I'm trying
thanks
@Ray `app/dashboard/(navbar)/layout.tsx`
`app/dashboard/(navbar)/articales/page.tsx`
`app/dashboard/login.tsx`
ok then this should be enough
Greek HarehoundOP
Works perfectly fine