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
This commit is contained in:
Claude
2026-01-04 18:51:17 +00:00
parent 72b644250a
commit a19c2199b6
4 changed files with 22 additions and 21 deletions

View File

@@ -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");

View File

@@ -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);

View File

@@ -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");

View File

@@ -16,7 +16,7 @@ const router = createBrowserRouter([
),
},
{
path: "/npub:identifier",
path: "/npub1*",
element: (
<AppShell hideBottomBar>
<PreviewProfilePage />
@@ -24,7 +24,7 @@ const router = createBrowserRouter([
),
},
{
path: "/nevent:identifier",
path: "/nevent1*",
element: (
<AppShell hideBottomBar>
<PreviewEventPage />
@@ -32,7 +32,7 @@ const router = createBrowserRouter([
),
},
{
path: "/note:identifier",
path: "/note1*",
element: (
<AppShell hideBottomBar>
<PreviewEventPage />
@@ -40,7 +40,7 @@ const router = createBrowserRouter([
),
},
{
path: "/naddr:identifier",
path: "/naddr1*",
element: (
<AppShell hideBottomBar>
<PreviewAddressPage />