From ebe40f2f3e12835102e172ad6f4fc61580b1b981 Mon Sep 17 00:00:00 2001 From: "Lim\\jun" Date: Wed, 31 Jan 2024 16:26:36 +0900 Subject: [PATCH] =?UTF-8?q?Dashboard=20=EC=A4=91=EA=B0=84=EC=A0=80?= =?UTF-8?q?=EC=9E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/ScrollTop.js | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 egovframe-template-simple-react-contribution/src/components/ScrollTop.js diff --git a/egovframe-template-simple-react-contribution/src/components/ScrollTop.js b/egovframe-template-simple-react-contribution/src/components/ScrollTop.js new file mode 100644 index 0000000..e2e63f5 --- /dev/null +++ b/egovframe-template-simple-react-contribution/src/components/ScrollTop.js @@ -0,0 +1,26 @@ +import PropTypes from 'prop-types'; +import { useEffect } from 'react'; +import { useLocation } from 'react-router-dom'; + +// ==============================|| NAVIGATION - SCROLL TO TOP ||============================== // + +const ScrollTop = ({ children }) => { + const location = useLocation(); + const { pathname } = location; + + useEffect(() => { + window.scrollTo({ + top: 0, + left: 0, + behavior: 'smooth' + }); + }, [pathname]); + + return children || null; +}; + +ScrollTop.propTypes = { + children: PropTypes.node +}; + +export default ScrollTop; \ No newline at end of file