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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user