Dev Helpers
← Back

Parent route link

Place this file at components/ParentRouteLink.tsx in an App Router project.

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>;
}