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

Basename Not Included in href for Links in Left Navigation #4556

Open
SilenceLeo opened this issue Dec 24, 2024 · 4 comments
Open

Basename Not Included in href for Links in Left Navigation #4556

SilenceLeo opened this issue Dec 24, 2024 · 4 comments
Assignees
Labels
bug 🐛 Something doesn't work component: layout This is the name of the generic UI component, not the React module! scope: toolpad-core Abbreviated to "core"

Comments

@SilenceLeo
Copy link

SilenceLeo commented Dec 24, 2024

Steps to reproduce

When a basename is added to React Router,the href in the left-side navigation does not include the basename.
While everything works fine during regular navigation, the path is incorrect when opening links in a new window or tab.
e.g., right-click -> Open link in new tab

@toolpad/[email protected]

Current behavior

No response

Expected behavior

No response

Context

No response

Your environment

No response

Search keywords: navigation, routing, link, basename

@SilenceLeo SilenceLeo added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Dec 24, 2024
@apedroferreira
Copy link
Member

apedroferreira commented Dec 24, 2024

Hi, could you please share a reproduction / CodeSandbox or the specific configuration you're using for React Router and the navigation passed to AppProvider?

I wonder if just including the basename in the segments for navigation items would be enough, but if that solution isn't elegant enough we can try to come up with something better.

@Janpot
Copy link
Member

Janpot commented Dec 24, 2024

I wonder if just including the basename in the segments for navigation items would be enough, but if that solution isn't elegant enough we can try to come up with something better.

I believe this will need to be part of the router adapter. the DashboardLayout should not need to know about the basepath.

@SilenceLeo
Copy link
Author

Hi, could you please share a reproduction / CodeSandbox or the specific configuration you're using for React Router and the navigation passed to AppProvider?

const router = createBrowserRouter(
  [
    {
      Component: App,
      children: [
        {
          path: "",
          element: <Layout />,
          children: [
            {
              path: "",
              element: <Home />,
            },
            {
              path: "question",
              element: <QuestionList />,
            },
            {
              path: "question/:qid",
              element: <Question />,
            },
            {
              path: "exam_paper",
              element: <ExamPaperList />,
            },
            {
              path: "exam_paper/:pid",
              element: <ExamPaper />,
            },
          ],
        },
      ],
    },
  ],
  {
    basename: "/question-bank",
  }
);
const navigation: Navigation = [
  {
    title: 'Home',
    icon: <DashboardIcon />
  },
  {
    kind: 'divider'
  },
  {
    kind: 'header',
    title: 'Questions'
  },
  {
    segment: 'question',
    title: 'Questions',
    icon: <DescriptionIcon />,
    pattern: 'question{/:qid}*'
  },
  {
    segment: 'exam_paper',
    title: 'Exam Paper',
    icon: <NewspaperIcon />,
    pattern: 'exam_paper{/:pid}*'
  }
];

I wonder if just including the basename in the segments for navigation items would be enough, but if that solution isn't elegant enough we can try to come up with something better.

I tried placing the basename in the segments, but after clicking the navigation, it results in two layers of basename (e.g., Clicking "Questions" navigates to /question-bank/question-bank/question instead of /question-bank/question), which directly affects normal navigation behavior.

@apedroferreira
Copy link
Member

I tried placing the basename in the segments, but after clicking the navigation, it results in two layers of basename (e.g., Clicking "Questions" navigates to /question-bank/question-bank/question instead of /question-bank/question), which directly affects normal navigation behavior.

I see, I can confirm the issue.
Looks like we will need to add support for basename in the AppProvider for React Router, sorry for the inconvenience and thanks for reporting it!

@prakhargupta1 prakhargupta1 added scope: toolpad-core Abbreviated to "core" component: layout This is the name of the generic UI component, not the React module! bug 🐛 Something doesn't work and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jan 7, 2025
@Janpot Janpot moved this from Backlog to Planned in MUI Toolpad public roadmap Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work 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

4 participants