small tweak

This commit is contained in:
Rich Harris
2018-09-30 18:26:44 -04:00
parent b915bab070
commit 2e2b8dcd83

View File

@@ -1,16 +1,13 @@
import { select_route, navigate, cid } from '../app';
import { history, select_route, navigate, cid } from '../app';
export default function goto(href: string, opts = { replaceState: false }) {
const target = select_route(new URL(href, document.baseURI));
let promise;
if (target) {
promise = navigate(target, null).then(() => {});
if (history) history[opts.replaceState ? 'replaceState' : 'pushState']({ id: cid }, '', href);
} else {
location.href = href;
promise = new Promise(f => {}); // never resolves
history[opts.replaceState ? 'replaceState' : 'pushState']({ id: cid }, '', href);
return navigate(target, null).then(() => {});
}
return promise;
location.href = href;
return new Promise(f => {}); // never resolves
}