-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: properly handle redirects in prerendered pages #13365
Conversation
🦋 Changeset detectedLatest commit: f163920 The changes in this PR will be included in the next version bump. This PR includes changesets to release 11 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
if (redirectStatusCodes.has(response.status)) { | ||
// This isn't ideal but gets the job done as a fallback if the user can't | ||
// implement proper redirects via .htaccess or something else. This is the | ||
// approach used by Astro as well so there's some precedent. | ||
// https://github.com/withastro/roadmap/issues/466 | ||
// https://github.com/withastro/astro/blob/main/packages/astro/src/core/routing/3xx.ts | ||
let location = response.headers.get("Location"); | ||
// A short delay causes Google to interpret the redirect as temporary. | ||
// https://developers.google.com/search/docs/crawling-indexing/301-redirects#metarefresh | ||
let delay = response.status === 302 ? 2 : 0; | ||
html = `<!doctype html> | ||
<head> | ||
<title>Redirecting to: ${location}</title> | ||
<meta http-equiv="refresh" content="${delay};url=${location}"> | ||
<meta name="robots" content="noindex"> | ||
</head> | ||
<body> | ||
<a href="${location}"> | ||
Redirecting from <code>${normalizedPath}</code> to <code>${location}</code> | ||
</a> | ||
</body> | ||
</html>`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a prerendered document redirects we fall back on an http-equiv redirect
Heya, in an app started from the Cloudflare template I have an action for export const action = async ({ request }: Route.ActionArgs) => {
const formData = await request.formData();
if (formData.get('param')) {
return redirect(href('/some-page'));
}
return null;
}; In Does this PR fix this exact behavior, or is this something else? If this is not the right place to ask, can you please point me in the right direction? Thank you! |
@PetarMetodiev |
No description provided.