mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
* Ensure trailing slash is handled correctly with middleware * update source modifying * undo extra change
43 lines
881 B
JavaScript
43 lines
881 B
JavaScript
import { useRouter } from 'next/router'
|
|
import { useEffect } from 'react'
|
|
import { useState } from 'react'
|
|
|
|
export default function Page(props) {
|
|
const router = useRouter()
|
|
const [asPath, setAsPath] = useState(
|
|
router.isReady ? router.asPath : router.href
|
|
)
|
|
|
|
useEffect(() => {
|
|
if (router.isReady) {
|
|
setAsPath(router.asPath)
|
|
}
|
|
}, [router.asPath, router.isReady])
|
|
|
|
return (
|
|
<>
|
|
<p id="ssg">/blog/[slug]</p>
|
|
<p id="query">{JSON.stringify(router.query)}</p>
|
|
<p id="pathname">{router.pathname}</p>
|
|
<p id="as-path">{asPath}</p>
|
|
<p id="props">{JSON.stringify(props)}</p>
|
|
</>
|
|
)
|
|
}
|
|
|
|
export function getStaticProps({ params }) {
|
|
return {
|
|
props: {
|
|
now: Date.now(),
|
|
params,
|
|
},
|
|
}
|
|
}
|
|
|
|
export function getStaticPaths() {
|
|
return {
|
|
paths: ['/ssg/first', '/ssg/hello'],
|
|
fallback: 'blocking',
|
|
}
|
|
}
|