autoformat
parent
aaa511fc3f
commit
bdbf46549d
|
@ -1,41 +1,41 @@
|
|||
import { createHashHistory } from "history";
|
||||
import type { HistorySource } from "svelte-navigator";
|
||||
|
||||
export default function(): HistorySource {
|
||||
const history = createHashHistory({window});
|
||||
let listeners = [];
|
||||
export default function (): HistorySource {
|
||||
const history = createHashHistory({ window });
|
||||
let listeners = [];
|
||||
|
||||
history.listen(location => {
|
||||
if (history.action === "POP") {
|
||||
listeners.forEach(listener => listener(location));
|
||||
}
|
||||
});
|
||||
history.listen((location) => {
|
||||
if (history.action === "POP") {
|
||||
listeners.forEach((listener) => listener(location));
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
get location() {
|
||||
return history.location as any;
|
||||
},
|
||||
addEventListener(name, handler) {
|
||||
if (name !== "popstate") return;
|
||||
listeners.push(handler);
|
||||
},
|
||||
removeEventListener(name, handler) {
|
||||
if (name !== "popstate") return;
|
||||
listeners = listeners.filter(fn => fn !== handler);
|
||||
},
|
||||
history: {
|
||||
get state() {
|
||||
return history.location.state;
|
||||
},
|
||||
pushState(state, title, uri) {
|
||||
history.push(uri, state);
|
||||
},
|
||||
replaceState(state, title, uri) {
|
||||
history.replace(uri, state);
|
||||
},
|
||||
go(to) {
|
||||
history.go(to);
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
return {
|
||||
get location() {
|
||||
return history.location as any;
|
||||
},
|
||||
addEventListener(name, handler) {
|
||||
if (name !== "popstate") return;
|
||||
listeners.push(handler);
|
||||
},
|
||||
removeEventListener(name, handler) {
|
||||
if (name !== "popstate") return;
|
||||
listeners = listeners.filter((fn) => fn !== handler);
|
||||
},
|
||||
history: {
|
||||
get state() {
|
||||
return history.location.state;
|
||||
},
|
||||
pushState(state, title, uri) {
|
||||
history.push(uri, state);
|
||||
},
|
||||
replaceState(state, title, uri) {
|
||||
history.replace(uri, state);
|
||||
},
|
||||
go(to) {
|
||||
history.go(to);
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue