Files
zk-data-agent/frontend/app/lib/claw-session-url.ts
T
2026-06-12 11:06:04 +08:00

26 lines
741 B
TypeScript

"use client";
export function readSessionIdFromUrl() {
if (typeof window === "undefined") return null;
const match = window.location.pathname.match(/^\/session\/([^/]+)$/);
if (!match?.[1]) return null;
try {
return decodeURIComponent(match[1]).trim() || null;
} catch {
return match[1].trim() || null;
}
}
export function pushSessionUrl(sessionId: string) {
if (typeof window === "undefined") return;
const target = `/session/${encodeURIComponent(sessionId)}`;
if (window.location.pathname === target) return;
window.history.pushState(null, "", target);
}
export function pushHomeUrl() {
if (typeof window === "undefined") return;
if (window.location.pathname === "/") return;
window.history.pushState(null, "", "/");
}