You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
any <a href="#anyhash">hello world</a> will sometimes cause the window.history.state become null, then the later visit will failed
but handle the click with inertia will cause unecessary network request, the hashchange event does not fire thanks to history.pushState
Steps to reproduce:
<a href="#1">hello world 1</a><a href="#2">hello world 2</a>
navigate around (not guaranteed to trigger, but chance is quite high)
my workaround (svelte 5)
import{createSubscriber}from'svelte/reactivity';import{on}from'svelte/events';import{router}from'@inertiajs/svelte';constsubscribe=createSubscriber((update)=>{returnon(window,'hashchange',update);});exportconstfragment={getvalue(){subscribe();returnwindow.location.hash;},setvalue(value){if(!value.startsWith('#')){value='#'+value;}if(value!==window.location.hash){constnewUrl=newURL(value,window.location.href);// inertia uses replace state internally when there is only hash changed, which is not really same as browser behaviourrouter.push({url: newUrl.href});window.dispatchEvent(newHashChangeEvent('hashchange'));}}};exportfunctionreplaceHash(value: string){if(!value.startsWith('#')){value='#'+value;}if(value!==window.location.hash){constnewUrl=newURL(value,window.location.href);router.replace({url: newUrl.href});window.dispatchEvent(newHashChangeEvent('hashchange'));}}document.body.addEventListener('click',((event: MouseEvent&{target: HTMLAnchorElement})=>{if(event.defaultPrevented||event.button!==0||event.ctrlKey||event.metaKey||event.shiftKey||event.target.tagName!=='A'||event.target.target==='_blank')return;consturl=newURL(event.target.href);if(url.origin===window.location.origin&&url.pathname===window.location.pathname&&url.search===window.location.search&&url.hash!==window.location.hash){event.preventDefault();fragment.value=url.hash;}})asany);
p/s: browser will push to history when hash changed, so this line really shouldn't be there
Versions:
@inertiajs/core
version: 2.0.3@inertiajs/svelte
version: 2.0.3Describe the problem:
any
<a href="#anyhash">hello world</a>
will sometimes cause thewindow.history.state
become null, then the later visit will failedbut handle the click with inertia will cause unecessary network request, the
hashchange
event does not fire thanks tohistory.pushState
Steps to reproduce:
<a href="#1">hello world 1</a>
<a href="#2">hello world 2</a>
my workaround (svelte 5)
p/s: browser will push to history when hash changed, so this line really shouldn't be there
inertia/packages/core/src/page.ts
Line 62 in 1b29f8a
The text was updated successfully, but these errors were encountered: