Use /r/* wildcard route for relay pages, supporting bare URLs with slashes

This commit is contained in:
Alex Gleason
2026-03-06 21:32:35 -06:00
parent 24e940ae63
commit fa484dc03d
3 changed files with 12 additions and 12 deletions
+1 -1
View File
@@ -107,7 +107,7 @@ export function AppRouter() {
<Route path="/ai-chat" element={<AIChatPage />} />
<Route path="/world" element={<WorldPage />} />
<Route path="/books" element={<BooksPage />} />
<Route path="/relay/*" element={<RelayPage />} />
<Route path="/r/*" element={<RelayPage />} />
<Route path="/i/*" element={<ExternalContentPage />} />
{/* NIP-19 route for npub1, note1, naddr1, nevent1, nprofile1 */}
+1 -1
View File
@@ -635,7 +635,7 @@ export function NoteContent({
return (
<Link
key={i}
to={`/relay/${token.url}`}
to={`/r/${token.url}`}
className="text-primary hover:underline break-all"
onClick={(e) => e.stopPropagation()}
>
+10 -10
View File
@@ -86,22 +86,22 @@ function useRelayFeed(relayUrl: string | undefined, kinds: number[]) {
export function RelayPage() {
const { config } = useAppContext();
const { '*': urlParam } = useParams();
const { '*': rawParam } = useParams();
const { feedSettings } = useFeedSettings();
const { muteItems } = useMuteList();
const kinds = getEnabledFeedKinds(feedSettings).filter((k) => !isRepostKind(k));
// Reconstruct the relay URL from the wildcard param
// Support both encoded URLs (/r/wss%3A%2F%2F...) and bare URLs (/r/wss://...).
const relayUrl = useMemo(() => {
if (!urlParam) return undefined;
// If the param already has a protocol, use it as-is
if (urlParam.startsWith('wss://') || urlParam.startsWith('ws://')) {
return urlParam;
if (!rawParam) return undefined;
// If the wildcard param has no "://", it's encoded — decode it.
const url = rawParam.includes('://') ? rawParam : decodeURIComponent(rawParam);
if (url.startsWith('wss://') || url.startsWith('ws://')) {
return url;
}
// Otherwise, prepend wss://
return `wss://${urlParam}`;
}, [urlParam]);
return `wss://${url}`;
}, [rawParam]);
// Derive a display hostname from the URL
const hostname = useMemo(() => {
@@ -130,7 +130,7 @@ export function RelayPage() {
description: info?.description ?? `Events from ${hostname}`,
});
if (!urlParam) {
if (!rawParam) {
return <NotFound />;
}