Skip to content

Nested routes in / don't get rendered #8685

Closed Answered by BenJenkinson
RodPaDev asked this question in Q&A
Discussion options

You must be logged in to vote

Would this do what you want?

import { useRoutes, Outlet } from 'react-router-dom';

const Example = () => {
  const element = useRoutes([
    {
      element: <App />,
      children: [
        {
          index: true,
          element: <Home />,
        },
        {
          path: '/copy',
          element: <Copy />,
        },
      ],
    },
  ]);

  return element;
};

const App = () => (
  <div>
    <p>As a "layout" route, "children" routes are rendered in the <code>&lt;Outlet&gt;</code></p>
    <Outlet />
  </div>
);

const Home = () => <div>This is the "home" route.</div>;

const Copy = () => <div>This is the "copy" route.</div>;

Changes from your question example

  • I removed the p…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@RodPaDev
Comment options

Answer selected by RodPaDev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants