-
-
Notifications
You must be signed in to change notification settings - Fork 251
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
Difference in <Link/> path serverside vs clientside #808
Comments
Yeah, sorry about that. Found out this was intended behaviour after posting this issue. Unfortunately, I need to have this working correctly on server-side, otherwise I'll have trouble with the SEO company we pay loads of money. I'm now using a custom component that renders the correct path server-side. Our setup is relatively simple and static so I won't expect any problems with that. |
@jbreemhaar I don't know if this solves your specific problem because I never experienced it, but perhaps it helps in some way, and it sounds similar to the direction you are taking :) I've looked at the I used this function P.S. The |
@jbreemhaar I had the same issue and I am using this workaround for now: import { type RedirectType, redirect as nextRedirect } from "next/navigation";
import { locales, pathnames, localePrefix, defaultLocale } from './config'
import NextLink from "next/link";
export const {
redirect,
getPathname: getPathname_
} = createLocalizedPathnamesNavigation({ locales, pathnames, localePrefix });
export const getPathname: typeof getPathname_ = ({ href, locale }) => {
const pathname = getPathname_({ href, locale });
let prefix = "";
if (locale !== defaultLocale) {
prefix = `/${locale}`;
}
return `${prefix}${pathname}`;
};
export const redirect: typeof redirect_ = (href, type) => {
const locale = useLocale();
const path = getPathname({ href, locale });
nextRedirect(path, type);
};
export function Link<Pathname extends keyof typeof pathnames>(
{ href, ...rest }: ComponentProps<typeof I18nLink<Pathname>>,
ref: ForwardedRef<ElementRef<typeof NextLink>>,
) {
const locale = useLocale();
// @ts-expect-error this is okay
const localizedHref = getPathname({ href, locale });
return <NextLink href={localizedHref} {...rest} ref={ref} />;
} Note: This won't work correctly if you have multiple domains |
Description
Hi!
First off, let me say thanks for this library. My current projects now needs localized pathnames which this lib offers, so thanks!
Unfortunately I'm encountering an issue with the next-intl
<Link/>
component rendering the localePrefix serverside althoughas-needed
is set as LocalePrefix. Clientside renders the correct path.E.g. serverside renders
/nl/over
vs serverside/over
.This seems to be fully reproducible. Running the example-app-router with localePrefix
as-needed
will result in the same problem.Any ideas?
Although kind of works for the end-user because it gets fixed by hydration and browsers with JS disabled will ultimately be redirected, it's not that nice to have in production and probably has some effect on SEO.
Mandatory reproduction URL (CodeSandbox or GitHub repository)
https://ndrx9l-3000.csb.app/
Reproduction description
Steps to reproduce:
Expected behaviour
Serverside should render the correct path when localePrefix = 'as-needed'.
The text was updated successfully, but these errors were encountered: