This document explains the routing setup in your React TypeScript project using react-router-dom
.
Layout
) → For authenticated users, includes sidebar & topbar..NonLayout
) → For unauthenticated users, such as login or error pages. src/routes/allRoutes.tsx
const routes: IRoute[] = [ { path: "/", component: <DashboardsPage /> }, { path: "/dashboards/analytics", component: <Analytics /> }, ]; const nonAuthRoutes: IRoute[] = [ { path: "/page/contact-us", component: <ContactUs /> }, { path: "/page/auth/signin-basic", component: <SignIn /> }, ]; export { routes, nonAuthRoutes };
src/routes/index.tsx
import { Route, Routes } from "react-router-dom"; import { nonAuthRoutes, routes } from "./allRoutes"; import NonLayout from "@src/layout/nonLayout"; import Layout from "@src/layout/layout"; const Routing = () => { return ( <Routes> {(routes || []).map((item, key) => ( <Route key={key} path={item.path} element={<Layout>{item.component}</Layout>} /> ))} {(nonAuthRoutes || []).map((item, key) => ( <Route key={key} path={item.path} element={<NonLayout>{item.component}</NonLayout>} /> ))} </Routes> ); }; export default Routing;
src/App.tsx
import { BrowserRouter } from "react-router-dom"; import Routing from "./routes/Routing"; function App() { return ( <Routing /> ); } export default App;
Be the first to know about new updates and exclusive discounts. No spam, just great offers!
How about
With over 7 years of experienced team, we specialize in delivering custom projects for startups, blue-chip companies, and government agencies. We have successfully completed over 250+ projects, providing tailored solutions that meet the unique needs of each client.
Hire Us© Domiex Created & Crafted by SRBThemes.