diff --git a/frontend/src/components/common/redirect.tsx b/frontend/src/components/common/redirect.tsx index e701146a6..bc47ab232 100644 --- a/frontend/src/components/common/redirect.tsx +++ b/frontend/src/components/common/redirect.tsx @@ -11,6 +11,7 @@ import React, { useEffect } from 'react' export interface RedirectProps { to: string + replace?: boolean } const logger = new Logger('Redirect') @@ -19,15 +20,16 @@ const logger = new Logger('Redirect') * Redirects the user to another URL. Can be external or internal. * * @param to The target URL + * @param replace Defines if the current browser history entry should be replaced or not */ -export const Redirect: React.FC = ({ to }) => { +export const Redirect: React.FC = ({ to, replace }) => { const router = useRouter() useEffect(() => { - router?.push(to).catch((error: Error) => { + ;(replace ? router.replace(to) : router.push(to)).catch((error: Error) => { logger.error(`Error while redirecting to ${to}`, error) }) - }) + }, [replace, router, to]) return (