Clean all URLs by default in URL state sync

This commit is contained in:
Andrew Kingston 2023-08-23 10:32:24 +01:00
parent a54c5b7222
commit d486a89ee7
2 changed files with 7 additions and 7 deletions

View File

@ -65,6 +65,10 @@ export const syncURLToState = options => {
params = res.params params = res.params
} }
} }
// Clean URL
if (url?.endsWith("/index")) {
url = url.replace("/index", "")
}
log("Navigating to", url, "with params", params) log("Navigating to", url, "with params", params)
cachedGoto(url, params) cachedGoto(url, params)
} }

View File

@ -13,12 +13,8 @@
$: params = routify.params $: params = routify.params
$: routeComponentId = $params.componentId $: routeComponentId = $params.componentId
const cleanUrl = url => { // Hide new component panel whenever component ID changes
// Strip trailing slashes const closeNewComponentPanel = url => {
if (url?.endsWith("/index")) {
url = url.replace("/index", "")
}
// Hide new component panel whenever component ID changes
if (url?.endsWith("/new")) { if (url?.endsWith("/new")) {
url = url.replace("/new", "") url = url.replace("/new", "")
} }
@ -40,7 +36,7 @@
fallbackUrl: "../", fallbackUrl: "../",
store, store,
routify, routify,
beforeNavigate: cleanUrl, beforeNavigate: closeNewComponentPanel,
}) })
onDestroy(stopSyncing) onDestroy(stopSyncing)