Routing
This document describes the routing system used in the project, including how to add new pages, dynamic routes, and best practices.
Router Used
- The project uses React Router (or Next.js router, if applicable) for client-side routing.
- All routes are defined in
src/routes/or in the main app file (e.g.,App.tsx).
Adding New Routes
- Create a new page/component in
src/pages/(or the appropriate domain folder). - Add a route in the router configuration:
- For React Router: Add a
<Route path="/your-path" element={<YourComponent />} />inApp.tsxorsrc/routes/. - For Next.js: Add a new file in
pages/(e.g.,pages/your-path.tsx).
- For React Router: Add a
- Link to the route using
<Link to="/your-path">orrouter.push('/your-path').
Dynamic Routes
- Use
:paramsyntax for dynamic segments (e.g.,/orgs/:orgId). - Access route params using hooks (e.g.,
useParamsin React Router,useRouterin Next.js).
Route Protection
- Use auth context or guards to protect private routes.
- Redirect unauthenticated users to login or a public page.
- Example (React Router):tsx
{ isAuthenticated ? <PrivatePage /> : <Navigate to="/login" />; }
Best Practices
- Keep route definitions organized and grouped by domain.
- Use lazy loading for large pages/components.
- Avoid deeply nested routes unless necessary.
- Use centralized route constants for paths if possible.
For more, see ARCHITECTURE.md or ask a maintainer.