Unverified Commit 565c5b20 authored by Lee Robinson's avatar Lee Robinson Committed by GitHub

docs: small tweaks (#59638)

Just some random cleanup I wanted to do.
parent 2e14537f
......@@ -83,6 +83,8 @@ export default async function NotFound() {
}
```
If you need to use Client Component hooks like `usePathname` to display content based on the path, you must fetch data on the client-side instead.
## Version History
| Version | Changes |
......
......@@ -11,7 +11,7 @@ description: API Reference for the useParams hook.
import { useParams } from 'next/navigation'
export default function ExampleClientComponent() {
const params = useParams()
const params = useParams<{ tag: string; item: string }>()
// Route -> /shop/[tag]/[item]
// URL -> /shop/shoes/nike-air-max-97
......
---
title: Setting up Vitest with Next.js
nav_title: Jest
nav_title: Vitest
description: Learn how to set up Next.js with Vitest and React Testing Library - two popular unit testing libraries.
source: app/building-your-application/testing/vitest
---
......
......@@ -10,23 +10,59 @@ The `redirect` value returned from your `getStaticProps` or `getServerSideProps`
Make sure you return the proper values for the `redirect` value.
```js filename="pages/blog/[slug].js"
export const getStaticProps = ({ params }) => {
if (params.slug === 'deleted-post') {
```tsx filename="pages/index.tsx" switcher
import type { InferGetStaticPropsType, GetStaticProps } from 'next'
type Repo = {
name: string
stargazers_count: number
}
export const getStaticProps = (async (context) => {
const res = await fetch('https://api.github.com/repos/vercel/next.js')
const repo = await res.json()
if (!repo) {
return {
redirect: {
permanent: true, // or false
destination: '/some-location',
permanent: false, // or true
destination: '/404',
},
}
}
return {
props: {},
return { props: { repo } }
}) satisfies GetStaticProps<{
repo: Repo
}>
export default function Page({
repo,
}: InferGetStaticPropsType<typeof getStaticProps>) {
return repo.stargazers_count
}
```
```jsx filename="pages/index.js" switcher
export async function getStaticPaths() {
const res = await fetch('https://api.github.com/repos/vercel/next.js')
const repo = await res.json()
if (!repo) {
return {
redirect: {
permanent: false, // or true
destination: '/404',
},
}
}
return { props: { repo } }
}
export default function Page(props) {}
export default function Page({ repo }) {
return repo.stargazers_count
}
```
## Useful Links
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment