refactor: preserve URL search params during navigation

Introduce `useNavigateWithParams` to ensure that existing URL search
parameters are maintained when navigating between pages. This is
applied to the Article component, FileTree, and journal links to
prevent losing state (like session or player info) during client-side
navigation.

Also intercepts markdown anchor links in the Article component to use
client-side navigation.
This commit is contained in:
2026-07-07 23:26:44 +08:00
parent 48776424a7
commit 779722fe85
4 changed files with 54 additions and 9 deletions
+3 -3
View File
@@ -6,7 +6,7 @@
*/
import { Component } from "solid-js";
import { useNavigate } from "@solidjs/router";
import { useNavigateWithParams } from "../../useNavigateWithParams";
import { z } from "zod";
import { registerMessageType } from "../registry";
import { journalSetState } from "../../stores/journalStream";
@@ -22,7 +22,7 @@ export type LinkPayload = z.infer<typeof schema>;
function fileNameFromPath(path: string): string {
const parts = path.split("/").filter(Boolean);
return parts[parts.length - 1] || path;
return decodeURIComponent(parts[parts.length - 1] || path);
}
/** Encode a path, preserving / separators but encoding each segment */
@@ -42,7 +42,7 @@ function slugToTitle(slug: string): string {
}
const RevealLink: Component<LinkPayload> = (p) => {
const navigate = useNavigate();
const navigate = useNavigateWithParams();
const target = () => {
let t = encodePath(p.path);