navigation
navigation copied to clipboard
document.location.href should be updated before intercept handler is run.
Prerequisites
- [x] I have written a descriptive issue title
- [x] I have searched existing issues to ensure it has not already been reported
Version (i.e. v2.x.x)
1.0.1-alpha.209
Node.js version (i.e. 18.x, or N/A)
No response
Operating system
None
Operating system version (i.e. 20.04, 11.3, 10, or N/A)
No response
Description
As per MDN ("The URL has already changed"), the page URL should be already changed when the interception handler is called.
Steps to Reproduce
window.navigation.addEventListener('navigate', ev => {
ev.intercept({
async handler() {
console.log(document.location.pathname)
}
})
})
window.navigation.navigate('/xyz')
Expected Behavior
In Chrome, this logs '/xyz'. With the polyfill, it logs whatever the pathname was before.
This appears to be because history is updated only on current entry change
https://github.com/virtualstate/navigation/blob/6f66ed21bb050345e937002f847fbcdc9eb30b7e/src/get-polyfill.ts#L756-L779
I'll investigate updating this earlier in the polyfill and then reverting the change if it was aborted.