@keenmate/svelte-spa-router 1.0.5 → 1.0.7
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 -27
- package/constants.js +1 -1
- package/package.json +1 -1
package/Router.svelte
CHANGED
|
@@ -40,10 +40,10 @@
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
location = "/" + window.location.pathname.substring(basePath.length).replace(/^\//, "")
|
|
43
|
-
// console.log("SAPA ROUTER Parsing querystring", window.location.search)
|
|
44
43
|
if (window.location.search) {
|
|
45
44
|
querystring = window.location.search.substring(1)
|
|
46
45
|
}
|
|
46
|
+
console.log("SPA router getting location", window.location, location, querystring)
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
return {location, querystring}
|
|
@@ -54,15 +54,14 @@
|
|
|
54
54
|
*/
|
|
55
55
|
export const loc = readable(
|
|
56
56
|
null,
|
|
57
|
-
|
|
58
|
-
function start(set) {
|
|
57
|
+
set => {
|
|
59
58
|
set(getLocation())
|
|
60
59
|
|
|
61
60
|
const eventName = get(HashRoutingEnabled) ?
|
|
62
61
|
"hashchange" :
|
|
63
62
|
SvelteSPARouterNavigationEvent
|
|
64
63
|
// console.log("Setting loc")
|
|
65
|
-
const update
|
|
64
|
+
const update = () => {
|
|
66
65
|
console.log("Updating location", getLocation())
|
|
67
66
|
set(getLocation())
|
|
68
67
|
}
|
|
@@ -167,24 +166,25 @@
|
|
|
167
166
|
else {
|
|
168
167
|
window.dispatchEvent(new Event("hashchange"))
|
|
169
168
|
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
// console.log("get(location)", get(location))
|
|
172
|
+
// if (location_ !== get(location)) {
|
|
173
|
+
if (!location_.startsWith(basePath)) {
|
|
174
|
+
location_ = joinPaths(basePath, location_)
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
console.log(
|
|
178
|
+
"Before navigate",
|
|
179
|
+
window.history,
|
|
180
|
+
doNavigate,
|
|
181
|
+
newHistoryState,
|
|
182
|
+
undefined,
|
|
183
|
+
location_
|
|
184
|
+
)
|
|
185
|
+
// window.history.pushState(newHistoryState, undefined, location)
|
|
186
|
+
doNavigate(newHistoryState, undefined, location_)
|
|
187
|
+
// }
|
|
188
188
|
|
|
189
189
|
window.dispatchEvent(new Event(SvelteSPARouterNavigationEvent))
|
|
190
190
|
}
|
|
@@ -273,22 +273,24 @@
|
|
|
273
273
|
if (!opts.disabled) {
|
|
274
274
|
scrollstateHistoryHandler(ev.currentTarget.getAttribute("href"))
|
|
275
275
|
}
|
|
276
|
-
}
|
|
277
|
-
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
// console.log("Handling link click event")
|
|
278
279
|
const linkTarget = ev.target.getAttribute("target")
|
|
279
280
|
if (linkTarget && linkTarget !== "_self") {
|
|
280
|
-
console.log("Link has special target attr, opening href instead")
|
|
281
|
+
// console.log("Link has special target attr, opening href instead")
|
|
282
|
+
ev.preventDefault()
|
|
281
283
|
// prevent pushState when link is perhaps going outside of this window
|
|
282
284
|
window.open(node.getAttribute("href"), linkTarget)
|
|
283
285
|
|
|
284
286
|
return
|
|
285
287
|
}
|
|
286
288
|
if (ev.ctrlKey || ev.shiftKey || ev.metaKey) {
|
|
287
|
-
console.log("Modifier key has been held while opening link, keeping behaviour intact")
|
|
289
|
+
// console.log("Modifier key has been held while opening link, keeping behaviour intact")
|
|
288
290
|
return
|
|
289
291
|
}
|
|
290
292
|
|
|
291
|
-
console.log("Custom link operation is in place")
|
|
293
|
+
// console.log("Custom link operation is in place")
|
|
292
294
|
ev.preventDefault()
|
|
293
295
|
|
|
294
296
|
const shouldReplace = typeof opts !== "string" && opts.shouldReplace
|
package/constants.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SvelteSPARouterNavigationEvent =
|
|
1
|
+
export const SvelteSPARouterNavigationEvent = "popstate"
|