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

Unable to Use 'router.replace' with Custom Locale Parameter #420

Closed
PixelPage-YT opened this issue Jul 23, 2023 · 5 comments
Closed

Unable to Use 'router.replace' with Custom Locale Parameter #420

PixelPage-YT opened this issue Jul 23, 2023 · 5 comments
Labels
bug Something isn't working reproduction-missing unconfirmed Needs triage.

Comments

@PixelPage-YT
Copy link

Description

I know this is not directly related to next-intl, but it's recommended in the docs and i need an alternative.
I encountered an issue while attempting to use the 'router.replace' method in combination with a custom 'locale' parameter. However, I received an error message stating, "Argument of type '{ locale: string; }' is not assignable to parameter of type 'Url | undefined'. Object literal may only specify known properties, and 'locale' does not exist in type 'UrlObject'.ts(2345)."

Mandatory reproduction URL (CodeSandbox or GitHub repository)

https://codesandbox.io/p/sandbox/next-intl-bug-template-forked-yow8ep

Reproduction description

  1. Follow the documentation link provided (https://next-intl-docs.vercel.app/docs/routing/navigation#userouter) to learn about the recommended approach for routing with internationalization using 'router.replace'.
  2. Implement the 'router.replace' method with the 'pathname' and 'locale' parameters in your Next.js application as described in the documentation.
  3. Observe the TypeScript error mentioned above when attempting to compile the application.

Expected behaviour

The user should be redirected to the current page with the correct translation provided.

@PixelPage-YT PixelPage-YT added bug Something isn't working unconfirmed Needs triage. labels Jul 23, 2023
@PixelPage-YT
Copy link
Author

PixelPage-YT commented Jul 23, 2023

This is my temporary solution:

// e is the selected locale
router.push(e + '/' + pathname.replace(/\/(de|en)?\/?/,'/'))

@github-actions
Copy link

Thank you for your report.

Unfortunately, the reproduction is missing, 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 bug report 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 either a CodeSandbox or a public GitHub repository where the issue can be reproduced.

Please make sure:

  1. If you've linked to a CodeSandbox, make sure to save the latest changes.
  2. If you've linked to a GitHub repository, make sure that you've committed and pushed the latest changes.
  3. Linking to other resources, e.g. to the docs, unfortunately doesn't help to reproduce your issue.

@github-actions
Copy link

github-actions bot commented Aug 2, 2023

This issue has been automatically closed because it is missing a reproduction and there hasn't been any activity for 7 days. If the problem persists, please create a new bug report.

@github-actions github-actions bot added the Stale label Aug 2, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Aug 2, 2023
@gc7g
Copy link

gc7g commented Apr 22, 2024

I'm experiencing the exact same problem

@mp3por
Copy link

mp3por commented May 21, 2024

Me too :)

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

4 participants