From fc98022a90068c1afd31927d34360fbb24c38bb8 Mon Sep 17 00:00:00 2001 From: Frikky Date: Wed, 20 Sep 2023 17:00:47 +0200 Subject: [PATCH] Fixed removeQuery problem --- frontend/src/components/ScrollToTop.jsx | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/frontend/src/components/ScrollToTop.jsx b/frontend/src/components/ScrollToTop.jsx index fa4464f4..a023181b 100755 --- a/frontend/src/components/ScrollToTop.jsx +++ b/frontend/src/components/ScrollToTop.jsx @@ -2,6 +2,20 @@ import { useEffect } from "react"; //import { withRouter } from "react-router-dom"; import { useLocation } from "react-router-dom"; +export const removeQuery = (query) => { + const urlSearchParams = new URLSearchParams(window.location.search) + const params = Object.fromEntries(urlSearchParams.entries()) + if (params[query] !== undefined) { + delete params[query] + } else { + return + } + + const queryString = Object.keys(params).map(key => key + '=' + params[key]).join('&') + const newurl = window.location.protocol + "//" + window.location.host + window.location.pathname + '?' + queryString + window.history.pushState({path:newurl},'',newurl) +} + // ensures scrolling happens in the right way on different pages and when changing function ScrollToTop({ getUserNotifications, curpath, setCurpath, history }) { let location = useLocation();