Open this example in the interactive library
Source code
"use client";
// components/ParentRouteLink.tsx
import Link from "next/link";
import { usePathname } from "next/navigation";
export default function ParentRouteLink({ href = "/studio" }: { href?: string } = {}) {
const path = usePathname();
const parent = path.split("/").filter(Boolean).slice(0, -1).join("/");
return <Link href={"/" + parent}>Up one level</Link>;
}
