Skip to content

Commit

Permalink
Merge pull request #25 from vkrol/remove-redundant-origin-check
Browse files Browse the repository at this point in the history
Get rid of redundant origin check
  • Loading branch information
ai authored Sep 4, 2023
2 parents bb6c5f9 + 7328dc7 commit 8369928
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
16 changes: 7 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,13 @@ export function createRouter(routes, opts = {}) {
let click = event => {
let link = event.target.closest('a')
if (isRouterClick(event, link)) {
if (link.origin === location.origin) {
event.preventDefault()
let changed = location.hash !== link.hash
router.open(link.pathname + link.search)
if (changed) {
location.hash = link.hash
if (link.hash === '' || link.hash === '#') {
window.dispatchEvent(new HashChangeEvent('hashchange'))
}
event.preventDefault()
let changed = location.hash !== link.hash
router.open(link.pathname + link.search)
if (changed) {
location.hash = link.hash
if (link.hash === '' || link.hash === '#') {
window.dispatchEvent(new HashChangeEvent('hashchange'))
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@
"import": {
"./index.js": "{ createRouter }"
},
"limit": "822 B"
"limit": "817 B"
},
{
"name": "Search Params",
"import": {
"./index.js": "{ createSearchParams }"
},
"limit": "520 B"
"limit": "519 B"
}
],
"clean-publish": {
Expand Down

0 comments on commit 8369928

Please sign in to comment.