mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 10:34:17 +00:00
improve navigation effects
This commit is contained in:
parent
7995ba452d
commit
6e30d97248
@ -165,31 +165,46 @@ const NavigationController = (props) => {
|
|||||||
state = {}
|
state = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
app.location.last = window.location
|
||||||
|
|
||||||
|
await navigate(to, {
|
||||||
|
state
|
||||||
|
})
|
||||||
|
|
||||||
app.eventBus.emit("router.navigate", to, {
|
app.eventBus.emit("router.navigate", to, {
|
||||||
state,
|
state,
|
||||||
})
|
})
|
||||||
|
|
||||||
app.location.last = window.location
|
return {
|
||||||
|
to,
|
||||||
return navigate(to, {
|
state,
|
||||||
state
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function backLocation() {
|
async function backLocation() {
|
||||||
app.eventBus.emit("router.navigate")
|
|
||||||
|
|
||||||
app.location.last = window.location
|
|
||||||
|
|
||||||
return window.history.back()
|
return window.history.back()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function onHistoryChange() {
|
||||||
|
setTimeout(() => {
|
||||||
|
app.eventBus.emit("router.navigate", window.location.pathname, {
|
||||||
|
state: window.location.state,
|
||||||
|
})
|
||||||
|
}, 0)
|
||||||
|
}
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
app.location = {
|
app.location = {
|
||||||
last: window.location,
|
last: window.location,
|
||||||
push: setLocation,
|
push: setLocation,
|
||||||
back: backLocation,
|
back: backLocation,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
window.addEventListener("popstate", onHistoryChange)
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener("popstate", onHistoryChange)
|
||||||
|
}
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
return props.children
|
return props.children
|
||||||
|
Loading…
x
Reference in New Issue
Block a user