Add popstate listener to improve home navigation
This commit is contained in:
parent
4ba051726e
commit
bdc044368e
|
@ -81,11 +81,18 @@ const useContractPage = () => {
|
||||||
if (!username || !contractSlug) setContract(undefined)
|
if (!username || !contractSlug) setContract(undefined)
|
||||||
else {
|
else {
|
||||||
// Show contract if route is to a contract: '/[username]/[contractSlug]'.
|
// Show contract if route is to a contract: '/[username]/[contractSlug]'.
|
||||||
getContractFromSlug(contractSlug).then(setContract)
|
getContractFromSlug(contractSlug).then((contract) => {
|
||||||
|
const path = location.pathname.split('/').slice(1)
|
||||||
|
const [_username, contractSlug] = path
|
||||||
|
// Make sure we're still on the same contract.
|
||||||
|
if (contract?.slug === contractSlug) setContract(contract)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addEventListener('popstate', updateContract)
|
||||||
|
|
||||||
const { pushState, replaceState } = window.history
|
const { pushState, replaceState } = window.history
|
||||||
|
|
||||||
window.history.pushState = function () {
|
window.history.pushState = function () {
|
||||||
|
@ -101,6 +108,7 @@ const useContractPage = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
|
removeEventListener('popstate', updateContract)
|
||||||
window.history.pushState = pushState
|
window.history.pushState = pushState
|
||||||
window.history.replaceState = replaceState
|
window.history.replaceState = replaceState
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user