import { createBrowserRouter } from "react-router-dom";
import Content from "../../Public/pages/Content/Content";
import { Home } from "@mui/icons-material";
const Route = createBrowserRouter([
{
path: "/",
element: <Home></Home>, // working
children: [
{
path: "/",
element: <Content /> children is not working
}
]
},
])
export default Route;
Content Should show on the page but it’s not working and it’s not showing any error
2
Answers
You are rendering the child with the same
path
, that’s not possible. How would React-Router know which route to render 😉You’ll need to add an unique
path
to the child, for example let’s make the url/content
:For more information and examples, please check the
createBrowserRouter()
documentation.const Route = createBrowserRouter([
{
path: "/",
element: ,
children: [
{
path: "/content",
element: , },
],
},
]);