11import React from 'react' ;
22import ReactDOM from 'react-dom/client' ;
33import { createBrowserRouter , RouterProvider } from 'react-router-dom' ;
4- // import Root from './routes/root';
54import Index from './routes' ;
65import ErrorPage from './error-page' ;
76import Contact from './routes/contact' ;
87import Root , {
98 loader as rootLoader ,
109 action as rootAction ,
1110} from './routes/root' ;
12- import { loader as contactLoader , action as contactAction } from './routes/contact' ;
11+ import {
12+ loader as contactLoader ,
13+ action as contactAction ,
14+ } from './routes/contact' ;
1315import './index.css' ;
1416import EditContact from './routes/edit' ;
1517import { action as editAction } from './routes/edit' ;
16- // import DeleteContact from './routes/destroy'
1718import { action as deleteAction } from './routes/destroy' ;
1819
1920const router = createBrowserRouter ( [
@@ -25,11 +26,11 @@ const router = createBrowserRouter([
2526 action : rootAction ,
2627 children : [
2728 { index : true , element : < Index /> } ,
28- {
29+ {
2930 path : 'contacts/:contactId' ,
3031 element : < Contact /> ,
3132 loader : contactLoader ,
32- action : contactAction
33+ action : contactAction ,
3334 } ,
3435 {
3536 path : 'contacts/:contactId/edit' ,
@@ -43,9 +44,38 @@ const router = createBrowserRouter([
4344 action : deleteAction ,
4445 errorElement : < div > Oops! There was an error.</ div > ,
4546 } ,
47+ {
48+ errorElement : < ErrorPage /> ,
49+ children : [
50+ { index : true , element : < Index /> } ,
51+ {
52+ path : 'contacts/:contactId' ,
53+ element : < Contact /> ,
54+ loader : contactLoader ,
55+ action : contactAction ,
56+ } ,
57+ ] ,
58+ } ,
4659 ] ,
4760 } ,
4861] ) ;
62+ /* Also we can configure the routes with JSX
63+ using by importing createRoutesFromElements in react-router-dom.
64+ for example:
65+ const router = createBrowserRouter(
66+ createRoutesFromElements(
67+ <Route
68+ path="/"
69+ element={<Root />}
70+ loader={rootLoader}
71+ action={rootAction}
72+ errorElement={<ErrorPage />}
73+ >
74+ {...child routes configurations}
75+ </Route>
76+ )
77+ )
78+ */
4979
5080ReactDOM . createRoot ( document . getElementById ( 'root' ) ) . render (
5181 < React . StrictMode >
0 commit comments