Merge pull request #45 from dergigi/fix-a-path-regression

fix: gate /a/:naddr rewrite to crawlers to prevent refresh redirect
This commit is contained in:
Gigi
2025-11-07 23:16:28 +01:00
committed by GitHub
3 changed files with 20 additions and 2 deletions

View File

@@ -60,7 +60,7 @@ ${articleTags}
</head> </head>
<body> <body>
<noscript> <noscript>
<p>Redirecting to <a href="/">Boris</a>...</p> <p>Redirecting to <a href="/a/${naddr}">Boris</a>...</p>
</noscript> </noscript>
<script> <script>
(function(){ (function(){
@@ -69,7 +69,8 @@ ${articleTags}
if (window.location.pathname !== p) { if (window.location.pathname !== p) {
history.replaceState(null, '', p); history.replaceState(null, '', p);
} }
window.location.replace('/'); var sep = window.location.search ? '&' : '?';
window.location.replace(p + sep + '_spa=1');
} catch (e) {} } catch (e) {}
})(); })();
</script> </script>

View File

@@ -755,6 +755,16 @@ function App() {
} }
}, [showToast]) }, [showToast])
// Strip _spa query parameter from URL after SPA loads
useEffect(() => {
const url = new URL(window.location.href)
if (url.searchParams.has('_spa')) {
url.searchParams.delete('_spa')
const path = url.pathname + (url.search ? url.search : '') + url.hash
window.history.replaceState(null, '', path)
}
}, [])
if (!eventStore || !accountManager || !relayPool) { if (!eventStore || !accountManager || !relayPool) {
return ( return (
<div className="loading"> <div className="loading">

View File

@@ -9,6 +9,13 @@
} }
}, },
"rewrites": [ "rewrites": [
{
"source": "/a/:naddr",
"destination": "/index.html",
"has": [
{ "type": "query", "key": "_spa", "value": "1" }
]
},
{ {
"source": "/a/:naddr", "source": "/a/:naddr",
"destination": "/api/article-og?naddr=:naddr" "destination": "/api/article-og?naddr=:naddr"