Skip to content
This repository was archived by the owner on Sep 23, 2026. It is now read-only.
This repository was archived by the owner on Sep 23, 2026. It is now read-only.

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

Closed

Description

@SilenceLeo

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/core@0.11.0

Current behavior

No response

Expected behavior

No response

Context

No response

Your environment

No response

Search keywords: navigation, routing, link, basename

Activity

  1. apedroferreira commented on Dec 24, 2024

    @apedroferreira
    Collaborator

    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.

  2. Janpot commented on Dec 24, 2024

    @Janpot
    Member

    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.

  3. SilenceLeo commented on Dec 25, 2024

    @SilenceLeo
    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.

  4. apedroferreira commented on Jan 6, 2025

    @apedroferreira
    Collaborator

    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!

  5. moved this from Backlog to Planned in Toolpad public roadmapon Jan 13, 2025
  6. github-actions commented on Feb 24, 2025

    @github-actions

    This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue.
    Now, if you have additional information related to this issue or things that could help future readers, feel free to leave a comment.

    Note

    @SilenceLeo How did we do? Your experience with our support team matters to us. If you have a moment, please share your thoughts in this short Support Satisfaction survey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions