Next.js Discord

Discord Forum

How can we get path name without "use client"

Unanswered
Huntaway posted this in #help-forum
Open in Discord
HuntawayOP
hello, how can we get pathnmae without client componet.

9 Replies

@@ts-ignore you cannot
HuntawayOP
here a issue
"use client";

import { usePathname } from "next/navigation";
import Navbar from "@/components/Navbar";

export default function NavbarRouting() {
    const pathname = usePathname();
    const matchPathname = pathname.match(/^\/dashboard\/.*/);

    if (!matchPathname) {
        return <Navbar />
    } else {
        return <></>
    }
}
in navbar file its without "use client"
so i am using await there
but it give me error
Error: async/await is not yet supported in Client Components, only Server Components. This error is often caused by accidentally adding `'use client'` to a module that was originally written for the server.
navbar file is like
import { getSession } from "@/lib/functions";
import NavbarComponent from "@/clientComponents/navbarComponent";
import { use } from "react";

export default function Navbar() {
    const sessions = use(getSession());
    return <NavbarComponent session={sessions.data} />
}
what i do now