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 shouldOpenSidebar = isDesktop ? true : open;
|
||||||
|
|
||||||
const openSidebar = () => {
|
const openSidebar = () => {
|
||||||
|
if (!isDesktop) {
|
||||||
setOpen(true);
|
setOpen(true);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const closeSidebar = () => {
|
const closeSidebar = () => {
|
||||||
|
if (!isDesktop) {
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
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 clsx from 'clsx';
|
||||||
import { TFunction } from 'i18next';
|
import { TFunction } from 'i18next';
|
||||||
import useServer from '@features/ServerPage/libs/ServerContext/useServer';
|
import useServer from '@features/ServerPage/libs/ServerContext/useServer';
|
||||||
|
@ -31,8 +32,8 @@ export interface Props {
|
||||||
t: TFunction;
|
t: TFunction;
|
||||||
className?: string;
|
className?: string;
|
||||||
open: boolean;
|
open: boolean;
|
||||||
onClose: React.ReactEventHandler<{}>;
|
onClose: () => void;
|
||||||
onOpen: React.ReactEventHandler<{}>;
|
onOpen: () => void;
|
||||||
variant?: DrawerProps['variant'];
|
variant?: DrawerProps['variant'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +41,7 @@ const Sidebar = ({ t, className, open, variant, onClose, onOpen }: Props) => {
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const { key } = useServer();
|
const { key } = useServer();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
const { pathname } = useLocation();
|
||||||
const routes: Route[] = [
|
const routes: Route[] = [
|
||||||
{
|
{
|
||||||
name: t('pageLayout.sidebar.routes.dashboard'),
|
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 (
|
return (
|
||||||
<SwipeableDrawer
|
<SwipeableDrawer
|
||||||
anchor="left"
|
anchor="left"
|
||||||
|
|
Reference in New Issue
Block a user