Add popstate listener to improve home navigation

This commit is contained in:
James Grugett 2022-07-29 16:52:35 -07:00
parent 4ba051726e
commit bdc044368e

View File

@ -81,11 +81,18 @@ const useContractPage = () => {
if (!username || !contractSlug) setContract(undefined)
else {
// 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
window.history.pushState = function () {
@ -101,6 +108,7 @@ const useContractPage = () => {
}
return () => {
removeEventListener('popstate', updateContract)
window.history.pushState = pushState
window.history.replaceState = replaceState
}