FPSMS-frontend
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

56 lines
1.4 KiB

  1. "use client";
  2. import Breadcrumbs from "@mui/material/Breadcrumbs";
  3. import Typography from "@mui/material/Typography";
  4. import Link from "next/link";
  5. import MUILink from "@mui/material/Link";
  6. import { usePathname } from "next/navigation";
  7. const pathToLabelMap: { [path: string]: string } = {
  8. "": "Overview",
  9. "/projects": "Projects",
  10. "/projects/create": "Create Project",
  11. "/tasks": "Task Template",
  12. "/tasks/create": "Create Task Template",
  13. "/settings/qcItem": "Qc Item",
  14. "/settings/rss": "Rough Schedule Setting",
  15. "/scheduling/rough": "Rough Scheduling",
  16. "/scheduling/detail": "Detail Scheduling",
  17. };
  18. const Breadcrumb = () => {
  19. const pathname = usePathname();
  20. const segments = pathname.split("/");
  21. return (
  22. <Breadcrumbs>
  23. {segments.map((segment, index) => {
  24. const href = segments.slice(0, index + 1).join("/");
  25. const label = pathToLabelMap[href] || segment;
  26. if (index === segments.length - 1) {
  27. return (
  28. <Typography key={index} color="text.primary">
  29. {label}
  30. </Typography>
  31. );
  32. } else {
  33. return (
  34. <MUILink
  35. underline="hover"
  36. color="inherit"
  37. key={index}
  38. component={Link}
  39. href={href || "/"}
  40. >
  41. {label}
  42. </MUILink>
  43. );
  44. }
  45. })}
  46. </Breadcrumbs>
  47. );
  48. };
  49. export default Breadcrumb;