Next.js-重新導向(router)

很熟悉的東西。

簡述

Next 中也有提供 router 的功能,非常有 React 的味道:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import Link from 'next/link'
import { useRouter } from 'next/router'
import React, { useEffect } from 'react'

export default function NotFound() {
const router = useRouter()

useEffect(() => {
setTimeout(() => {
router.push('/')
}, 2000)
}, [])

return (
<div className='not-found'>
<h1>Ooops...</h1>
<h2>That page cannot be found :(</h2>
<p>
Go back to the{' '}
<Link href='/'>
<a>Homepage</a>
</Link>
</p>
</div>
)
}
Next.js-Router Hooks Next.js-404 頁面
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×