Skip to content
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

Site tries to route to /undefined #1600

Closed
3 tasks done
GregorGabric opened this issue Dec 10, 2024 · 3 comments
Closed
3 tasks done

Site tries to route to /undefined #1600

GregorGabric opened this issue Dec 10, 2024 · 3 comments
Labels
bug Something isn't working reproduction-missing unconfirmed Needs triage.

Comments

@GregorGabric
Copy link

Description

I get this error inside the console: GET https://[site-url]/undefined 404 (Not Found)

Is this a known issue, did i miss adding something maybe? I can't really find anyone else with this problem

routing.ts

import { createNavigation } from "next-intl/navigation";
import { defineRouting } from "next-intl/routing";

const locales = ["eng", "slo", "ita", "hrv", "bos"] as const;

export type EnabledLocale = (typeof locales)[number];
export const routing = defineRouting({
  // A list of all locales that are supported
  locales,

  localePrefix: "always",
  // Used when no locale matches
  defaultLocale: "slo",
  pathnames: {
    "/": "/",
    "/about": {
      slo: "/o-nas",
      eng: "/about",
      ita: "/chi-siamo",
      hrv: "/o-nama",
      bos: "/o-nama",
    },
    "/contact": {
      slo: "/kontakt",
      eng: "/contact",
      ita: "/contattaci",
      hrv: "/kontakt",
      bos: "/kontakt",
    },
  },
});

export const { Link, redirect, usePathname, useRouter, getPathname } =
  createNavigation(routing);

export type Pathnames = keyof typeof routing.pathnames;
export type Locale = (typeof routing.locales)[number];

request.ts

import { getRequestConfig } from "next-intl/server";
import type { EnabledLocale } from "./routing";
import { routing } from "./routing";

export default getRequestConfig(async ({ requestLocale }) => {
  // This typically corresponds to the `[locale]` segment
  let locale = (await requestLocale) as EnabledLocale | undefined;

  // Ensure that a valid locale is used
  if (!locale || !routing.locales.includes(locale)) {
    locale = routing.defaultLocale;
  }

  return {
    locale,
    messages: (await import(`../../messages/${locale}.json`)).default,
  };
});

Verifications

Mandatory reproduction URL

https://pelicon-test-1.vercel.app/eng

Reproduction description

Navigate to the site, first error is the described one

Expected behaviour

Not getting this error, redirect shouldn't try to go to /undefined

@GregorGabric GregorGabric added bug Something isn't working unconfirmed Needs triage. labels Dec 10, 2024
Copy link

Thank you for your report!

Unfortunately, the reproduction is missing or incomplete, and as such we cannot investigate this issue. Please add a reproduction to the issue, otherwise it will be closed automatically.

Templates:

Creating a good reproduction takes time.

To help us resolve the issue quickly, please simplify the reproduction as much as possible by removing any unnecessary code, files, and dependencies that are not directly related to the problem. The easier it is for us to see the issue, the faster we can help you.

Apart from the reproduction, make sure to include the precise steps on how to reproduce the issue, e.g.:

  1. Open reproduction
  2. Click on …
  3. See error: …

Thank you for your understanding!

FAQ

"I've included a reproduction, what is missing?"

This comment might have been added because your reproduction doesn't point to a destination where the issue can be reproduced. Please make sure that the latest changes were saved in the reproduction and that the link is correct.

@amannn
Copy link
Owner

amannn commented Dec 11, 2024

As a side note, your locales are not valid. If you require non-standard locales as prefixes, you can consider setting up custom prefixes as necessary (next-intl will warn against invalid locales in the future).

@GregorGabric
Copy link
Author

I corrected the locales and the problems went away, thank you
I was trying to make the mapping easier as i get three letter locales from crowdin :D
thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working reproduction-missing unconfirmed Needs triage.
Projects
None yet
Development

No branches or pull requests

2 participants