From adbb5fca95ee59589942436ee1c4288377c4cd8c Mon Sep 17 00:00:00 2001 From: srgooglo Date: Wed, 7 Sep 2022 11:14:36 +0200 Subject: [PATCH] fix router `setLocation` --- packages/app/src/router.jsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/app/src/router.jsx b/packages/app/src/router.jsx index 9acd9ea6..82954bcc 100644 --- a/packages/app/src/router.jsx +++ b/packages/app/src/router.jsx @@ -72,7 +72,16 @@ export const InternalRouter = withRouter((props) => { window.app.eventBus.emit("transitionDone", event) }) - props.history.setLocation = (to, state, delay) => { + props.history.setLocation = (to, state = {}, delay = 150) => { + // clean double slashes + to = to.replace(/\/{2,}/g, "/") + + // if state is a number, it's a delay + if (typeof state !== "object") { + delay = state + state = {} + } + const lastLocation = props.history.lastLocation if (typeof lastLocation !== "undefined" && lastLocation?.pathname === to && lastLocation?.state === state) { @@ -91,7 +100,6 @@ export const InternalRouter = withRouter((props) => { }, state) props.history.lastLocation = window.location - }, delay ?? defaultTransitionDelay) }