Skip to content

Commit 029262b

Browse files
committed
feat: Add route guard
1 parent 1b90b03 commit 029262b

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

CLAUDE.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,12 @@ const routes = useRoutes([
5353
{ path: "/about", element: <About /> },
5454
{ path: "/services", element: <Services /> },
5555
{ path: "/contact", element: <Contact /> },
56+
{ path: "*", element: <Navigate to="/" replace /> }, // Catch-all route
5657
]);
5758
```
5859

60+
**Catch-all Route**: Any invalid/unmatched paths automatically redirect to home (src/App.tsx:16)
61+
5962
### Component Organization
6063
All components follow a barrel export pattern:
6164
- **Structure**: `[ComponentName].tsx` + `index.ts` in same directory
@@ -103,6 +106,7 @@ All components follow a barrel export pattern:
103106
2. Create barrel export: `src/app/pages/[page-name]/index.ts` with `export { default } from "./PageName"`
104107
3. Import in `src/App.tsx`: `import PageName from "./app/pages/page-name"`
105108
4. Add to routes array in `AppRoutes`: `{ path: "/page-name", element: <PageName /> }`
109+
- **Important**: Add new routes BEFORE the catch-all route (`path: "*"`)
106110
5. Add navigation link in `Header.tsx` navLinks array
107111
6. Add footer link in `Footer.tsx` if needed
108112

src/App.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BrowserRouter, useRoutes } from "react-router-dom";
1+
import { BrowserRouter, Navigate, useRoutes } from "react-router-dom";
22
import Home from "./app/pages/home";
33
import About from "./app/pages/about";
44
import Services from "./app/pages/services";
@@ -13,6 +13,7 @@ const AppRoutes = () => {
1313
{ path: "/about", element: <About /> },
1414
{ path: "/services", element: <Services /> },
1515
{ path: "/contact", element: <Contact /> },
16+
{ path: "*", element: <Navigate to="/" replace /> },
1617
]);
1718
return routes;
1819
};

0 commit comments

Comments
 (0)