File tree Expand file tree Collapse file tree 3 files changed +71
-2
lines changed Expand file tree Collapse file tree 3 files changed +71
-2
lines changed Original file line number Diff line number Diff line change 1+ import { useRouteError } from "react-router-dom" ;
2+
3+ export default function ErrorPage ( ) {
4+ const error = useRouteError ( ) ;
5+ console . error ( error ) ;
6+
7+ return (
8+ < div id = "error-page" >
9+ < h1 > Oops!</ h1 >
10+ < p > Sorry, an unexpected error has occurred.</ p >
11+ < p >
12+ < i > { error . statusText || error . message } </ i >
13+ </ p >
14+ </ div >
15+ ) ;
16+ }
Original file line number Diff line number Diff line change 11import React from 'react'
22import ReactDOM from 'react-dom/client'
3- import App from './App.jsx'
3+ import { createBrowserRouter , RouterProvider } from 'react-router-dom'
4+ import Root from './routes/root'
5+ import ErrorPage from './error-page'
6+ // import App from './App.jsx'
47import './index.css'
58
9+ const router = createBrowserRouter ( [
10+ { path : '/' ,
11+ element : < Root /> ,
12+ errorElement : < ErrorPage /> ,
13+ }
14+ ] )
15+
616ReactDOM . createRoot ( document . getElementById ( 'root' ) ) . render (
717 < React . StrictMode >
8- < App />
18+ < RouterProvider router = { router } />
919 </ React . StrictMode > ,
1020)
Original file line number Diff line number Diff line change 1+ export default function Root ( ) {
2+ return (
3+ < >
4+ < div id = "sidebar" >
5+ < h1 > React Router Contacts</ h1 >
6+ < div >
7+ < form id = "search-form" role = "search" >
8+ < input
9+ id = "q"
10+ aria-label = "Search contacts"
11+ placeholder = "Search"
12+ type = "search"
13+ name = "q"
14+ />
15+ < div
16+ id = "search-spinner"
17+ aria-hidden
18+ hidden = { true }
19+ />
20+ < div
21+ className = "sr-only"
22+ aria-live = "polite"
23+ > </ div >
24+ </ form >
25+ < form method = "post" >
26+ < button type = "submit" > New</ button >
27+ </ form >
28+ </ div >
29+ < nav >
30+ < ul >
31+ < li >
32+ < a href = { `/contacts/1` } > Your Name</ a >
33+ </ li >
34+ < li >
35+ < a href = { `/contacts/2` } > Your Friend</ a >
36+ </ li >
37+ </ ul >
38+ </ nav >
39+ </ div >
40+ < div id = "detail" > </ div >
41+ </ >
42+ ) ;
43+ }
You can’t perform that action at this time.
0 commit comments