breadcrumbManage.tsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import React from "react";
  2. import { NavigateFunction } from "react-router";
  3. import type { Location } from "@remix-run/router";
  4. export default ({
  5. setPlaceholder,
  6. navigate,
  7. location,
  8. }: {
  9. setPlaceholder: React.Dispatch<React.SetStateAction<any>>;
  10. navigate: NavigateFunction;
  11. location: Location;
  12. }) => {
  13. const calculateFn = ({ title = "", path = "", isCallBack = true }) => {
  14. if (isCallBack) {
  15. return {
  16. title: title,
  17. path,
  18. onClick: () => {
  19. navigate(path, {
  20. replace: true,
  21. });
  22. },
  23. };
  24. }
  25. return {
  26. title: title,
  27. };
  28. };
  29. // 文件管理 的面包屑配置
  30. if (location.pathname === "/") {
  31. setPlaceholder([
  32. calculateFn({
  33. title: "文件管理",
  34. isCallBack: false,
  35. }),
  36. ]);
  37. }
  38. // 文件详情 的面包屑配置
  39. if (/^\/calculate\/[0-9]?$/.test(location.pathname)) {
  40. setPlaceholder([
  41. calculateFn({
  42. title: "文件管理",
  43. }),
  44. calculateFn({ title: "文件详情", isCallBack: false }),
  45. ]);
  46. }
  47. // 重复文件 的面包屑配置
  48. if (/^\/calculate-list\/[0-9]?$/.test(location.pathname)) {
  49. setPlaceholder([
  50. calculateFn({
  51. title: "文件管理",
  52. }),
  53. calculateFn({
  54. title: "文件详情",
  55. path: `${location.pathname}`.replace(/-list/g, ""),
  56. }),
  57. calculateFn({ title: "重复文件", isCallBack: false }),
  58. ]);
  59. }
  60. // 管理文件 的面包屑配置
  61. if (/^\/files-manage\/[0-9]?$/.test(location.pathname)) {
  62. setPlaceholder([
  63. calculateFn({
  64. title: "文件管理",
  65. }),
  66. calculateFn({
  67. title: "文件详情",
  68. path: `${location.pathname}`.replace(/files-manage/g, "calculate"),
  69. }),
  70. calculateFn({ title: "管理文件", isCallBack: false }),
  71. ]);
  72. }
  73. // 聊天 的面包屑配置
  74. if (/^\/chat/.test(location.pathname)) {
  75. setPlaceholder([
  76. calculateFn({ title: "chat", isCallBack: false }),
  77. ]);
  78. }
  79. };