BackButton.js 695 B

123456789101112131415161718192021222324252627282930
  1. // components/BackButton.js
  2. "use client";
  3. import { Button } from "@nextui-org/react";
  4. import { useRouter } from "next/navigation";
  5. export default function BackButton({ currentPath, isAdmin = false }) {
  6. const router = useRouter();
  7. const handleBackNavigation = () => {
  8. const pathArray = currentPath.split("/").filter(Boolean);
  9. if (pathArray.length > 1) {
  10. pathArray.pop();
  11. const basePath = isAdmin ? "/admin-view" : "/niederlassung";
  12. router.push(`${basePath}/${pathArray.join("/")}`);
  13. }
  14. };
  15. return (
  16. <Button
  17. variant="flat"
  18. size="sm"
  19. color="default"
  20. className="hover:bg-sky-500 hover:text-white"
  21. onClick={handleBackNavigation}
  22. >
  23. Zurück
  24. </Button>
  25. );
  26. }