Skip to content

Commit

Permalink
feat: 完善404页面
Browse files Browse the repository at this point in the history
  • Loading branch information
c0dedance committed Oct 30, 2023
1 parent e98f60a commit f5ce9fe
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,12 @@ export async function renderPage({
</html>`.trim()
console.log(`Rendering page in server side...`)
await Promise.all(
routes.map(async (r) => {
[
...routes,
{
path: '/404', // 生成 404.html
},
].map(async (r) => {
const helmetContext = {
context: {},
} as HelmetData
Expand Down
40 changes: 40 additions & 0 deletions src/runtime/theme-default/Layout/NotFoundLayout/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
export function NotFoundLayout() {
return (
<div
m="auto t-50"
p="t-16 x-6 b-24 sm:t-24 x-8 b-40"
text="center"
flex="center col"
>
<p text="6xl" font="semibold">
404
</p>
<h1 pt="3" text="xl" font="bold" className="leading-5">
PAGE NOT FOUND
</h1>
<div
m="t-6 x-auto b-4.5"
w="16"
style={{ height: '1px' }}
bg="divider-default"
/>

<div pt="5">
<a
inline-block=""
border="1px solid brand"
rounded="2xl"
p="y-1 x-4"
text="sm brand"
font-medium=""
transition="border-color duration-300 color duration-300"
hover="border-color-brand-dark color-brand-dark"
href={'/'}
aria-label="go to home"
>
Take me home
</a>
</div>
</div>
)
}
3 changes: 2 additions & 1 deletion src/runtime/theme-default/Layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Helmet } from 'react-helmet-async'
import { Nav } from '../components/Nav'
import { HomeLayout } from './HomeLayout'
import { DocLayout } from './DocLayout'
import { NotFoundLayout } from './NotFoundLayout'
import { usePageData } from '../../'
import '../styles/base.css'
import '../styles/vars.css'
Expand All @@ -17,7 +18,7 @@ export function Layout() {
} else if (pageType === 'doc') {
return <DocLayout />
} else {
return <div>404 页面</div>
return <NotFoundLayout />
}
}
return (
Expand Down

0 comments on commit f5ce9fe

Please sign in to comment.