From 0c9cf3688f936418fdb33bac5180ef858851fbf3 Mon Sep 17 00:00:00 2001 From: Uri Shaked Date: Sun, 17 Mar 2024 23:48:14 +0200 Subject: [PATCH] fix: descending into subcircuit replaces full url with just the file name #4 --- src/LibraryLoader.ts | 4 +++- src/index.ts | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/LibraryLoader.ts b/src/LibraryLoader.ts index 3d09f64..3d51058 100644 --- a/src/LibraryLoader.ts +++ b/src/LibraryLoader.ts @@ -10,7 +10,8 @@ export interface ILibraryDefinition { } export class LibraryLoader { - readonly cache = new Map(); + private readonly cache = new Map(); + readonly pathToUrl = new Map(); baseURL?: string; @@ -54,6 +55,7 @@ export class LibraryLoader { const url = new URL(path, githubURLToRaw(this.baseURL)); const result = await fetch(url); if (result.ok) { + this.pathToUrl.set(path, url.toString()); return result; } } diff --git a/src/index.ts b/src/index.ts index 5a7939a..a351259 100644 --- a/src/index.ts +++ b/src/index.ts @@ -88,7 +88,7 @@ renderer.onComponentClick.listen(async (path) => { } const newParams = new URLSearchParams(window.location.search); - newParams.set('file', path); + newParams.set('file', libraryLoader.pathToUrl.get(path) ?? path); history.pushState({ path }, '', '?' + newParams.toString()); await render(path); });