improve navigation effects

This commit is contained in:
SrGooglo 2024-09-15 03:33:28 +00:00
parent 7995ba452d
commit 6e30d97248

View File

@ -165,31 +165,46 @@ const NavigationController = (props) => {
state = {}
}
app.location.last = window.location
await navigate(to, {
state
})
app.eventBus.emit("router.navigate", to, {
state,
})
app.location.last = window.location
return navigate(to, {
state
})
return {
to,
state,
}
}
async function backLocation() {
app.eventBus.emit("router.navigate")
app.location.last = window.location
return window.history.back()
}
async function onHistoryChange() {
setTimeout(() => {
app.eventBus.emit("router.navigate", window.location.pathname, {
state: window.location.state,
})
}, 0)
}
React.useEffect(() => {
app.location = {
last: window.location,
push: setLocation,
back: backLocation,
}
window.addEventListener("popstate", onHistoryChange)
return () => {
window.removeEventListener("popstate", onHistoryChange)
}
}, [])
return props.children