'React Router V6 Not rendering pages
I am trying to get my routes working from my nav bar but no pages get rendered. My follow is as follows:
App.tsx:
<div>
<Routes>
<Route path={login} element={<LoginPage />} />
</Routes>
<Routes>
<Route path='/' element={<Dashboard />}/>
</Routes>
</div>
Dashboard.tsx:
export default function Dashboard() {
const mainPanel = React.createRef();
const getRoutes = (routes: any) => {
return routes.map((prop: any, key: number) => {
if (prop.collapse) {
return getRoutes(prop.views);
}
if (prop.layout) {
console.log(prop.component)
console.log(key)
return (
<Route
path={prop.layout + prop.path}
element={prop.component}
key={key}
/>
);
} else {
return null;
}
});
};
return (
<div className="wrapper">
<Sidebar activeColor={"danger"} protectedRoutes={ProtectedRoutes} LoggedInUser='Test' AccountRoutes={AccountRoute} />
<div className="main-panel" ref={mainPanel as React.RefObject<HTMLDivElement>}>
<TopNavbar />
<Routes>
{getRoutes(ProtectedRoutes)}
</Routes>
</div>
<Outlet />
</div>
);
}
and my Routes.ts:
export const ProtectedRoutes : ProtectedRoute[] = [
{
path: "dashboard",
name: "Dashboard",
icon: "nc-icon nc-paper",
component: DashboardPage,
layout: "/",
},
]
The follow was working but for some reason I am getting redirected to a blank page and in my console it says "No Routes Matched Location /dashboard"
Even without the Nav Bar if I go to the URL directly, it still does not work.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
