close sidebar after route change
This commit is contained in:
parent
d62fb59503
commit
893b433d44
|
@ -26,11 +26,15 @@ function PageLayout({ children }: Props) {
|
|||
const shouldOpenSidebar = isDesktop ? true : open;
|
||||
|
||||
const openSidebar = () => {
|
||||
setOpen(true);
|
||||
if (!isDesktop) {
|
||||
setOpen(true);
|
||||
}
|
||||
};
|
||||
|
||||
const closeSidebar = () => {
|
||||
setOpen(false);
|
||||
if (!isDesktop) {
|
||||
setOpen(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import React from 'react';
|
||||
import React, { useEffect } from 'react';
|
||||
import { useLocation } from 'react-router-dom';
|
||||
import clsx from 'clsx';
|
||||
import { TFunction } from 'i18next';
|
||||
import useServer from '@features/ServerPage/libs/ServerContext/useServer';
|
||||
|
@ -31,8 +32,8 @@ export interface Props {
|
|||
t: TFunction;
|
||||
className?: string;
|
||||
open: boolean;
|
||||
onClose: React.ReactEventHandler<{}>;
|
||||
onOpen: React.ReactEventHandler<{}>;
|
||||
onClose: () => void;
|
||||
onOpen: () => void;
|
||||
variant?: DrawerProps['variant'];
|
||||
}
|
||||
|
||||
|
@ -40,7 +41,7 @@ const Sidebar = ({ t, className, open, variant, onClose, onOpen }: Props) => {
|
|||
const classes = useStyles();
|
||||
const { key } = useServer();
|
||||
const theme = useTheme();
|
||||
|
||||
const { pathname } = useLocation();
|
||||
const routes: Route[] = [
|
||||
{
|
||||
name: t('pageLayout.sidebar.routes.dashboard'),
|
||||
|
@ -136,6 +137,10 @@ const Sidebar = ({ t, className, open, variant, onClose, onOpen }: Props) => {
|
|||
},
|
||||
];
|
||||
|
||||
useEffect(() => {
|
||||
onClose(); // eslint-disable-next-line
|
||||
}, [pathname]);
|
||||
|
||||
return (
|
||||
<SwipeableDrawer
|
||||
anchor="left"
|
||||
|
|
Reference in New Issue
Block a user