index.jsx 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import styles from './styles.module.scss';
  2. import {useEffect} from "react";
  3. import {NavLink, useLocation} from "react-router-dom";
  4. import {useSelector} from "react-redux";
  5. import {getRoute, getRouteChain} from "@features/mainSlice";
  6. import symbol from '@assets/symbol-defs.svg';
  7. import {useThemeProvider} from "@contexts/themeContext";
  8. import SvgIcon from "@components/SvgIcon";
  9. const i18n=global.i18n;
  10. const BreadCrumb=()=>{
  11. const {isMobile,showHeader,setShowHeader} = useThemeProvider();
  12. const {pathname} = useLocation();
  13. const chain=useSelector(getRouteChain(pathname));
  14. const currRoute=useSelector(getRoute(pathname));
  15. useEffect(() => {
  16. }, [pathname]);
  17. const renderDesktop=()=>{
  18. let len=chain.length;
  19. if (len<=1)return (<></>);
  20. return (
  21. <div className={styles.container}>
  22. <div className={styles.game_nav_path}>
  23. {
  24. chain.map((item,index)=>{
  25. let end=index===len-1;
  26. return (
  27. <>
  28. <NavLink key={index} to={`${!end?item.path:''}`} className={`${!end?styles.nav_hover:styles.nav_active}`}>
  29. <span>{i18n.t(item.title)}</span>
  30. </NavLink>
  31. {
  32. !end?(
  33. <svg className={styles.icon} key={"arrow_"+index}>
  34. <use xlinkHref={`${symbol}#icon_Arrow`} />
  35. </svg>
  36. ):(<></>)
  37. }
  38. </>
  39. )
  40. })
  41. }
  42. </div>
  43. </div>
  44. )
  45. }
  46. const renderMobile=()=>{
  47. let len=chain.length;
  48. if (len<=1){
  49. return (<></>);
  50. }
  51. return (
  52. <div className={styles.container_m}>
  53. <div className={styles.game_nav_path}>
  54. <NavLink to={currRoute.ppath}>
  55. <SvgIcon className={styles.icon} herf={"icon_Arrow"}/>
  56. {i18n.t(currRoute.title)}
  57. </NavLink>
  58. </div>
  59. </div>
  60. )
  61. }
  62. const renderBreadCrumb=()=>{
  63. return isMobile()?renderMobile():renderDesktop();
  64. }
  65. return (
  66. <>
  67. {
  68. renderBreadCrumb()
  69. }
  70. </>
  71. )
  72. }
  73. export default BreadCrumb;