-
Hi! import { getPathname as getI18nPathname, redirect } from "@/i18n/navigation";
export async function search(prevState: unknown, formData: FormData) {
//...
redirect({
href: {
pathname: "/news",
query: Object.fromEntries(searchParams),
hash: "#search-results" // 👈 how do I pass this here?
},
locale,
});
} I've tried using the redirect from import { defineRouting } from "next-intl/routing";
export const routing = defineRouting({
locales: ["hu"],
defaultLocale: "hu",
localeDetection: false,
localePrefix: "as-needed",
pathnames: {
"/": "/",
// ...
"/news": {
hu: "/hirek",
},
// ...
"/news/[slug]": {
hu: "/hirek/[slug]",
},
},
}); ex.: const locale = await getLocale();
const pathname = await getPathname({
pathname: "/news",
locale,
});
const url = `${pathname}?${searchParams.toString()}#search-results`;
redirect(url); the redirect happens and the Thank you for the help! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Hey, glad to hear if
The thing about URL hashes is that they are not sent to the server. I haven't used them in combination with Can you have a closer look with the network tools to see if a hash is correctly returned as part of the HTTP redirect with the There's also some nuance if you call I think some debugging might help here to understand the situation a bit better—potentially also with a minimal Next.js app that doesn't even use If you could share a demo URL that'd also be helpful! |
Beta Was this translation helpful? Give feedback.
Hey @amannn, thanks for the quick response, I've prepared a repo: https://github.com/lazakrisz/intl-redirect. I've also done some experimentation, which I left in the repo. I added two paths,
I'm also just noticing some weird flashing issues when the server action does the actual redirect. This could entirely be due to the same thing you have pointed out with next's
redirect
although I fail to understand why a server function's redirect would cause / trigger a client side redirect with all that "flashing" / "flickering". I did find this: vercel/next.js#57455 maybe its related? 🤔I checked the headers, and this is what I get back in the response headers: