@keenmate/svelte-spa-router 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Router.svelte +29 -25
- package/package.json +1 -1
package/Router.svelte
CHANGED
|
@@ -220,26 +220,6 @@
|
|
|
220
220
|
|
|
221
221
|
updateLink(node, opts)
|
|
222
222
|
|
|
223
|
-
if (!get(HashRoutingEnabled)) {
|
|
224
|
-
node.addEventListener("click", ev => {
|
|
225
|
-
ev.stopImmediatePropagation()
|
|
226
|
-
ev.preventDefault()
|
|
227
|
-
|
|
228
|
-
const linkTarget = ev.target.getAttribute("target")
|
|
229
|
-
if (linkTarget && linkTarget !== "_self") {
|
|
230
|
-
// prevent pushState when link is perhaps going outside of this window
|
|
231
|
-
window.open(node.getAttribute("href"), linkTarget)
|
|
232
|
-
|
|
233
|
-
return
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
const shouldReplace = typeof opts !== "string" && opts.shouldReplace
|
|
237
|
-
|
|
238
|
-
jediForcePush(node.getAttribute("href"), shouldReplace)
|
|
239
|
-
// window.dispatchEvent(new Event(SvelteSPARouterNavigationEvent))
|
|
240
|
-
}, {capture: true})
|
|
241
|
-
}
|
|
242
|
-
|
|
243
223
|
return {
|
|
244
224
|
update(updated) {
|
|
245
225
|
updated = linkOpts(updated)
|
|
@@ -286,11 +266,35 @@
|
|
|
286
266
|
}
|
|
287
267
|
|
|
288
268
|
node.setAttribute("href", href)
|
|
289
|
-
node.addEventListener("click",
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
269
|
+
node.addEventListener("click", ev => {
|
|
270
|
+
if (get(HashRoutingEnabled)) {
|
|
271
|
+
// Prevent default anchor onclick behaviour
|
|
272
|
+
ev.preventDefault()
|
|
273
|
+
if (!opts.disabled) {
|
|
274
|
+
scrollstateHistoryHandler(ev.currentTarget.getAttribute("href"))
|
|
275
|
+
}
|
|
276
|
+
} else {
|
|
277
|
+
console.log("Handling link click event")
|
|
278
|
+
const linkTarget = ev.target.getAttribute("target")
|
|
279
|
+
if (linkTarget && linkTarget !== "_self") {
|
|
280
|
+
console.log("Link has special target attr, opening href instead")
|
|
281
|
+
// prevent pushState when link is perhaps going outside of this window
|
|
282
|
+
window.open(node.getAttribute("href"), linkTarget)
|
|
283
|
+
|
|
284
|
+
return
|
|
285
|
+
}
|
|
286
|
+
if (ev.ctrlKey || ev.shiftKey || ev.metaKey) {
|
|
287
|
+
console.log("Modifier key has been held while opening link, keeping behaviour intact")
|
|
288
|
+
return
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
console.log("Custom link operation is in place")
|
|
292
|
+
ev.preventDefault()
|
|
293
|
+
|
|
294
|
+
const shouldReplace = typeof opts !== "string" && opts.shouldReplace
|
|
295
|
+
|
|
296
|
+
jediForcePush(node.getAttribute("href"), shouldReplace)
|
|
297
|
+
// window.dispatchEvent(new Event(SvelteSPARouterNavigationEvent))
|
|
294
298
|
}
|
|
295
299
|
})
|
|
296
300
|
}
|