Skip to content

Commit

Permalink
Ignore search params when comparing URLs
Browse files Browse the repository at this point in the history
Fixes #118
  • Loading branch information
imacrayon committed Dec 31, 2024
1 parent 7b9b68a commit 14ad86f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ async function handleLinks(event) {
link.isContentEditable ||
link.origin !== window.location.origin ||
link.getAttribute('href').startsWith('#') ||
(sameUrl(link, window.location) && link.hash)
(link.hash && samePath(link, window.location))
) return

event.preventDefault()
Expand Down Expand Up @@ -384,7 +384,7 @@ async function send(control, action = '', method = 'GET', body = null, enctype =
].find(key => key in control.target)
if (key !== 'xxx') {
plan = control.target[key]
if (!plan.ids.flat().includes('_self') || !response.redirected || !sameUrl(new URL(response.url), window.location)) {
if (!plan.ids.flat().includes('_self') || !response.redirected || !samePath(new URL(response.url), window.location)) {
PendingTargets.purge(response)
PendingTargets.plan(plan, response)
}
Expand Down Expand Up @@ -589,8 +589,8 @@ function dispatch(el, name, detail) {
)
}

function sameUrl(urlA, urlB) {
return (stripTrailingSlash(urlA.pathname) + urlA.search) === (stripTrailingSlash(urlB.pathname) + urlB.search)
function samePath(urlA, urlB) {
return stripTrailingSlash(urlA.pathname) === stripTrailingSlash(urlB.pathname)
}

function stripTrailingSlash(str) {
Expand Down

0 comments on commit 14ad86f

Please sign in to comment.