Skip to content

Commit

Permalink
添加新页面
Browse files Browse the repository at this point in the history
  • Loading branch information
zoujia committed May 30, 2024
1 parent 330b48a commit e94edba
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/error-page.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { useRouteError } from "react-router-dom";

export default function ErrorPage() {
const error = useRouteError();
console.log('>> ErrorPage error: ', error);

return (
<div id="error-page">
<h1>Oops!</h1>
<p>Sorry, an unexpected error has occurred.</p>
<p>
<i>{error.statusText || error.message}</i>
</p>
</div>
);
}
10 changes: 9 additions & 1 deletion src/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@ import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import { createBrowserRouter, RouterProvider } from 'react-router-dom';
import Root from './routes/root';
import ErrorPage from './error-page';
import Contact from './routes/contact';

const router = createBrowserRouter([
{
path: '/',
element: <div>Hello world!</div>
element: <Root />,
errorElement: <ErrorPage />
},
{
path: 'contacts/:contactId',
element: <Contact />
}
]);

Expand Down
24 changes: 24 additions & 0 deletions src/routes/contact.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export default function Contact() {
const contact = {
first: "Your",
last: "Name",
avatar: "https://placekitten.com/g/200/200",
twitter: "your_handle",
notes: "Some notes",
favorite: true,
};

return (
<div id="contact">
<div>
<img
key={contact.avatar}
src={contact.avatar || null}
/>
</div>
<div>
{/* TODO: */}
</div>
</div>
)
}
43 changes: 43 additions & 0 deletions src/routes/root.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
export default function Root() {
return (
<>
<div id="sidebar">
<h1>React Rooter Contacts</h1>
<div>
<form id="search-form" role="search">
<input
id="q"
aria-label="Search contacts"
placeholder="Search"
type="search"
name="q"
/>
<div
id="search-spinner"
aria-hidden
hidden={true}
/>
<div
className="sr-only"
aria-live="polite"
></div>
</form>
<form method="post">
<button type="submit">New</button>
</form>
</div>
<nav>
<ul>
<li>
<a href={`/contacts/1`}>Your Name</a>
</li>
<li>
<a href={`/contacts/2`}>Your Friend</a>
</li>
</ul>
</nav>
</div>
<div id="detail"></div>
</>
);
}

0 comments on commit e94edba

Please sign in to comment.