Skip to content

Build your personal knowledge base with Trilium Notes

refactor(client): document the location parameter of parseNavigationStateFromUrl

matt wilkieeb9ca5b5b612
diff --git a/apps/client/src/services/link.spec.ts b/apps/client/src/services/link.spec.ts
index 126f77b5f2..8087d66545 100644
--- a/apps/client/src/services/link.spec.ts
+++ b/apps/client/src/services/link.spec.ts
@@ -185,8 +185,7 @@ describe("parseNavigationStateFromUrl", () => {
happyDOM.setURL("https://host/?desktop");
try {
- const url = `${window.location.href.replace(/#.*/, "")}#root/WWaBNf3SSA1b`;
- expect(parseNavigationStateFromUrl(url))
+ expect(parseNavigationStateFromUrl("https://host/?desktop#root/WWaBNf3SSA1b"))
.toMatchObject({ notePath: "root/WWaBNf3SSA1b" });
} finally {
happyDOM.setURL(previousUrl);
diff --git a/apps/client/src/services/link.ts b/apps/client/src/services/link.ts
index 832ed508d4..b099e49368 100644
--- a/apps/client/src/services/link.ts
+++ b/apps/client/src/services/link.ts
@@ -332,6 +332,10 @@ function isExtraWindowUrl(url: string, hashIdx: number) {
return /[?&]extraWindow(?:[=&]|$)/.test(url.slice(0, hashIdx));
}
+/**
+ * Parses the navigation state in the hash of `url`. A full URL is internal when it addresses the
+ * document at `location` or has an accepted internal form. Any other URL is external: `{}`.
+ */
export function parseNavigationStateFromUrl(
url: string | undefined,
location: UrlParts = window.location