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

Navigation links with locale #4579

Open
oscar-b opened this issue Jan 8, 2025 · 6 comments
Open

Navigation links with locale #4579

oscar-b opened this issue Jan 8, 2025 · 6 comments
Labels
component: layout This is the name of the generic UI component, not the React module! scope: toolpad-core Abbreviated to "core"

Comments

@oscar-b
Copy link

oscar-b commented Jan 8, 2025

Steps to reproduce

Steps:

  1. Open this link to live example: (required)

Current behavior

Links in the navigation points to /admin instead of /en/admin, causing a full reload on navigation.

Expected behavior

Links should take the active locale into consideration, for instance linking to /en/admin.

Context

I'm trying to create navigation links with locales in the URL: https://nextjs.org/docs/app/building-your-application/routing/internationalization

The concept with segment for navigation makes it hard to for instance use getPathname() from next-intl as a halper.

I guess we'd need a way to change the navigation component that's used by AppProvider/DashboardLayout, or being able to provide a href instad of a segment.

Your environment

npx @mui/envinfo
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.

Search keywords: navigation, locale, react-intl, internationalization

@oscar-b oscar-b added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jan 8, 2025
@apedroferreira
Copy link
Member

apedroferreira commented Jan 9, 2025

Hi, we plan to make the navigation items overridable in #4413 which might help solve this issue.

But can you please share your navigation configuration or a reproduction if possible?
Just wondering why a navigation item segment with "en/admin" or even a dynamic "${locale}/admin" would not work.

@apedroferreira apedroferreira added scope: toolpad-core Abbreviated to "core" component: layout This is the name of the generic UI component, not the React module! and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jan 9, 2025
@oscar-b
Copy link
Author

oscar-b commented Jan 10, 2025

@apedroferreira Hi! Thanks, you're right, I mis-diagnosed this a bit, the root issue was that I imported the default AppProvider and not the nextjs variant 🤦🏻 Using ${locale}/post/${id} almost works now, however wrapping the same navigation items in a NavigationSubheaderItem changes the behavior. Is this a know issue?

https://codesandbox.io/p/sandbox/upbeat-sammet-dlvrrn

The nested links point to https://movies/lord-of-the-rings instead of https://dlvrrn.csb.app/movies/lord-of-the-rings

@apedroferreira
Copy link
Member

apedroferreira commented Jan 10, 2025

@apedroferreira Hi! Thanks, you're right, I mis-diagnosed this a bit, the root issue was that I imported the default AppProvider and not the nextjs variant 🤦🏻 Using ${locale}/post/${id} almost works now, however wrapping the same navigation items in a NavigationSubheaderItem changes the behavior. Is this a know issue?

https://codesandbox.io/p/sandbox/upbeat-sammet-dlvrrn

The nested links point to https://movies/lord-of-the-rings instead of https://dlvrrn.csb.app/movies/lord-of-the-rings

Ok, we have a release coming out right now that will change it to import { NextAppProvider } from '@toolpad/core/nextjs'; to help reduce this type of confusion!

Unfortunately I can't access your reproduction, it seems like it's a permissions issue?

@oscar-b
Copy link
Author

oscar-b commented Jan 11, 2025

Unfortunately I can't access your reproduction, it seems like it's a permissions issue?

Sorry, not used to Codesandbox, should be accessible now!

@Janpot
Copy link
Member

Janpot commented Jan 13, 2025

Likely the same issue as #4556. Caused by the rendered a not taking router specific behaviors into account, unlike the javascript based navigation.

@apedroferreira
Copy link
Member

Understood the issue now, it looks to be related to the way we build the paths from segments in a nested navigation.
Thanks for reporting it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: layout This is the name of the generic UI component, not the React module! scope: toolpad-core Abbreviated to "core"
Projects
Status: Planned
Development

No branches or pull requests

3 participants