File tree Expand file tree Collapse file tree 2 files changed +6
-1
lines changed
Expand file tree Collapse file tree 2 files changed +6
-1
lines changed Original file line number Diff line number Diff 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
6063All 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:
1031062 . Create barrel export: ` src/app/pages/[page-name]/index.ts ` with ` export { default } from "./PageName" `
1041073 . Import in ` src/App.tsx ` : ` import PageName from "./app/pages/page-name" `
1051084 . Add to routes array in ` AppRoutes ` : ` { path: "/page-name", element: <PageName /> } `
109+ - ** Important** : Add new routes BEFORE the catch-all route (` path: "*" ` )
1061105 . Add navigation link in ` Header.tsx ` navLinks array
1071116 . Add footer link in ` Footer.tsx ` if needed
108112
Original file line number Diff line number Diff line change 1- import { BrowserRouter , useRoutes } from "react-router-dom" ;
1+ import { BrowserRouter , Navigate , useRoutes } from "react-router-dom" ;
22import Home from "./app/pages/home" ;
33import About from "./app/pages/about" ;
44import 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} ;
You can’t perform that action at this time.
0 commit comments