Adds JS fallback for redirection

This commit is contained in:
Alicia Sykes 2024-05-11 23:13:50 +01:00
parent 91404d1c44
commit a5a277c20a

View File

@ -4,7 +4,13 @@ import '../../web-check-live/styles/index.css';
export const prerender = false; export const prerender = false;
const { pathname } = new URL(Astro.request.url) const { pathname, search } = new URL(Astro.request.url);
const searchUrl = new URLSearchParams(search).get('url');
if (searchUrl) {
Astro.redirect(`/check/${encodeURIComponent(searchUrl)}`);
}
--- ---
@ -14,6 +20,15 @@ const { pathname } = new URL(Astro.request.url)
<meta charset="UTF-8"> <meta charset="UTF-8">
</head> </head>
<body> <body>
<Main {pathname} client:visible /> <Main {pathname} client:load />
</body> </body>
</html> </html>
<script>
// Fallback, if Astro hasn't initialized the RC comp yet, use JS to redirect
const searchParams = new URL(window.location.href).searchParams;
if (searchParams.has('url')) {
window.location.href = `/check/${searchParams.get('url')}`;
}
</script>