diff --git a/src/lib/navigation/Redirect.tsx b/src/lib/navigation/Redirect.tsx index e164fa057..c4cc32594 100644 --- a/src/lib/navigation/Redirect.tsx +++ b/src/lib/navigation/Redirect.tsx @@ -1,8 +1,7 @@ import { FC, ReactElement, useLayoutEffect } from "react"; -import { changeState } from "lib/history"; import { Destination } from "./types"; -import { toHash, toURL } from "./utils"; +import { navigate } from "./navigate"; type RedirectProps = { to: Destination; @@ -18,7 +17,7 @@ const Redirect: FC = ({ fallback = null, }) => { useLayoutEffect( - () => changeState(toURL(toHash(to, merge)), !push), + () => navigate(to, { merge, replace: !push }), [to, merge, push], ); diff --git a/src/lib/navigation/navigate.ts b/src/lib/navigation/navigate.ts index 4847f06a7..338cc0806 100644 --- a/src/lib/navigation/navigate.ts +++ b/src/lib/navigation/navigate.ts @@ -3,7 +3,13 @@ import { changeState } from "lib/history"; import { Destination } from "./types"; import { toHash, toURL } from "./utils"; -export function navigate(to: Destination, action?: "replace") { - const url = toURL(toHash(to)); - changeState(url, action === "replace"); +export function navigate( + to: Destination, + opts: { + replace?: boolean; + merge?: boolean | string[]; + } = {}, +) { + const url = toURL(toHash(to, opts.merge)); + changeState(url, opts.replace); }