From a19c2199b67bff152932898cab01fdedbda98efa Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 4 Jan 2026 18:51:17 +0000 Subject: [PATCH] fix: correct route patterns for NIP-19 identifier previews The previous route patterns (/npub:identifier) conflicted with the catch-all /:actor/:identifier route and didn't properly match NIP-19 identifiers. Fixed by: 1. Using wildcard routes with correct prefixes: - /npub1* (not /npub:identifier) - /nevent1* (not /nevent:identifier) - /note1* (not /note:identifier) - /naddr1* (not /naddr:identifier) 2. Updated preview components to use params['*'] for wildcard capture: - Reconstruct full identifier as prefix + captured part - e.g., npub1 + params['*'] = npub107jk7htfv... This ensures routes properly match before the catch-all /:actor/:identifier route and correctly capture the full bech32-encoded identifier. Test URL: /npub107jk7htfv243u0x5ynn43scq9wrxtaasmrwwa8lfu2ydwag6cx2quqncxg --- src/components/pages/PreviewAddressPage.tsx | 8 ++++---- src/components/pages/PreviewEventPage.tsx | 19 ++++++++++--------- src/components/pages/PreviewProfilePage.tsx | 8 ++++---- src/root.tsx | 8 ++++---- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/components/pages/PreviewAddressPage.tsx b/src/components/pages/PreviewAddressPage.tsx index 388e76c..3eaa108 100644 --- a/src/components/pages/PreviewAddressPage.tsx +++ b/src/components/pages/PreviewAddressPage.tsx @@ -7,16 +7,16 @@ import { toast } from "sonner"; /** * PreviewAddressPage - Preview or redirect naddr identifiers - * Route: /naddr... + * Route: /naddr1* * For spellbooks (kind 30777), redirects to /:actor/:identifier * For all other addressable events, shows detail view */ export default function PreviewAddressPage() { - const { identifier } = useParams<{ identifier: string }>(); + const params = useParams<{ "*": string }>(); const navigate = useNavigate(); - // Reconstruct the full identifier - const fullIdentifier = identifier ? `naddr${identifier}` : undefined; + // Get the full naddr from the URL (naddr1 + captured part) + const fullIdentifier = params["*"] ? `naddr1${params["*"]}` : undefined; // Decode the naddr identifier (synchronous, memoized) const { decoded, error } = useNip19Decode(fullIdentifier, "naddr"); diff --git a/src/components/pages/PreviewEventPage.tsx b/src/components/pages/PreviewEventPage.tsx index 101ebbc..d792319 100644 --- a/src/components/pages/PreviewEventPage.tsx +++ b/src/components/pages/PreviewEventPage.tsx @@ -7,26 +7,27 @@ import { toast } from "sonner"; /** * PreviewEventPage - Preview a Nostr event from a nevent or note identifier - * Routes: /nevent..., /note... + * Routes: /nevent1*, /note1* * This page shows a single event view without affecting user's workspace layout */ export default function PreviewEventPage() { - const { identifier } = useParams<{ identifier: string }>(); + const params = useParams<{ "*": string }>(); const navigate = useNavigate(); const location = useLocation(); - // Determine the prefix based on the current path + // Determine the prefix based on the current path and reconstruct full identifier const fullIdentifier = useMemo(() => { - if (!identifier) return undefined; + const captured = params["*"]; + if (!captured) return undefined; const path = location.pathname; - if (path.startsWith("/nevent")) { - return `nevent${identifier}`; - } else if (path.startsWith("/note")) { - return `note${identifier}`; + if (path.startsWith("/nevent1")) { + return `nevent1${captured}`; + } else if (path.startsWith("/note1")) { + return `note1${captured}`; } return undefined; - }, [identifier, location.pathname]); + }, [params, location.pathname]); // Decode the event identifier (synchronous, memoized) const { decoded, error } = useNip19Decode(fullIdentifier); diff --git a/src/components/pages/PreviewProfilePage.tsx b/src/components/pages/PreviewProfilePage.tsx index 1668359..8b2a207 100644 --- a/src/components/pages/PreviewProfilePage.tsx +++ b/src/components/pages/PreviewProfilePage.tsx @@ -6,15 +6,15 @@ import { toast } from "sonner"; /** * PreviewProfilePage - Preview a Nostr profile from an npub identifier - * Route: /npub... + * Route: /npub1* * This page shows a single profile view without affecting user's workspace layout */ export default function PreviewProfilePage() { - const { identifier } = useParams<{ identifier: string }>(); + const params = useParams<{ "*": string }>(); const navigate = useNavigate(); - // Reconstruct the full identifier (react-router splits on /) - const fullIdentifier = identifier ? `npub${identifier}` : undefined; + // Get the full npub from the URL (npub1 + captured part) + const fullIdentifier = params["*"] ? `npub1${params["*"]}` : undefined; // Decode the npub identifier (synchronous, memoized) const { decoded, error } = useNip19Decode(fullIdentifier, "npub"); diff --git a/src/root.tsx b/src/root.tsx index 3cb5929..2833f3a 100644 --- a/src/root.tsx +++ b/src/root.tsx @@ -16,7 +16,7 @@ const router = createBrowserRouter([ ), }, { - path: "/npub:identifier", + path: "/npub1*", element: ( @@ -24,7 +24,7 @@ const router = createBrowserRouter([ ), }, { - path: "/nevent:identifier", + path: "/nevent1*", element: ( @@ -32,7 +32,7 @@ const router = createBrowserRouter([ ), }, { - path: "/note:identifier", + path: "/note1*", element: ( @@ -40,7 +40,7 @@ const router = createBrowserRouter([ ), }, { - path: "/naddr:identifier", + path: "/naddr1*", element: (