fix: mobile nav open
This commit is contained in:
parent
46999043a5
commit
5c7e1df051
|
|
@ -1,9 +1,9 @@
|
||||||
import { useEffect, useState } from 'react';
|
import { useCallback, useEffect, useState } from 'react';
|
||||||
|
import { usePathname } from 'next/navigation';
|
||||||
import { styled } from '@mui/material/styles';
|
import { styled } from '@mui/material/styles';
|
||||||
import { withAuthGuard } from 'src/hocs/with-auth-guard';
|
import { withAuthGuard } from 'src/hocs/with-auth-guard';
|
||||||
import { SideNav } from './side-nav';
|
import { SideNav } from './side-nav';
|
||||||
import { TopNav } from './top-nav';
|
import { TopNav } from './top-nav';
|
||||||
import { usePathname } from 'next/navigation';
|
|
||||||
|
|
||||||
const SIDE_NAV_WIDTH = 280;
|
const SIDE_NAV_WIDTH = 280;
|
||||||
|
|
||||||
|
|
@ -26,15 +26,23 @@ const LayoutContainer = styled('div')({
|
||||||
export const Layout = withAuthGuard((props) => {
|
export const Layout = withAuthGuard((props) => {
|
||||||
const { children } = props;
|
const { children } = props;
|
||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
const [openNav, setOpenNav] = useState(true);
|
const [openNav, setOpenNav] = useState(false);
|
||||||
|
|
||||||
useEffect(
|
const handlePathnameChange = useCallback(
|
||||||
() => {
|
() => {
|
||||||
if (openNav) {
|
if (openNav) {
|
||||||
setOpenNav(false);
|
setOpenNav(false);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[pathname, openNav]
|
[openNav]
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(
|
||||||
|
() => {
|
||||||
|
handlePathnameChange();
|
||||||
|
},
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
[pathname]
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
@ -51,4 +59,4 @@ export const Layout = withAuthGuard((props) => {
|
||||||
</LayoutRoot>
|
</LayoutRoot>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
Loading…
Reference in New Issue
Block a user