diff --git a/docs/advanced-features/codemods.md b/docs/advanced-features/codemods.md index 0a8b146b5cf286..512872ed3ea778 100644 --- a/docs/advanced-features/codemods.md +++ b/docs/advanced-features/codemods.md @@ -19,6 +19,30 @@ Codemods are transformations that run on your codebase programmatically. This al ## Next.js 13 +### `new-link` + +Safely removes `` from `next/link` or adds `legacyBehavior` prop. + +For example: + +```jsx +export default function Page() { + return ( + + About Us + + ) +} +``` + +Transforms into: + +```jsx +export default function Page() { + return About Us +} +``` + ### `next-image-to-legacy-image` Safely migrates existing Next.js 10, 11, 12 applications importing `next/image` to the renamed `next/legacy/image` import in Next.js 13. diff --git a/docs/advanced-features/i18n-routing.md b/docs/advanced-features/i18n-routing.md index c4ed2f39e00676..0e0ddf9cc30949 100644 --- a/docs/advanced-features/i18n-routing.md +++ b/docs/advanced-features/i18n-routing.md @@ -233,7 +233,7 @@ import Link from 'next/link' export default function IndexPage(props) { return ( - To /fr/another + To /fr/another ) } @@ -279,7 +279,7 @@ import Link from 'next/link' export default function IndexPage(props) { return ( - To /fr/another + To /fr/another ) } diff --git a/docs/api-reference/next.config.js/basepath.md b/docs/api-reference/next.config.js/basepath.md index 0df919b35a0575..696120ba4c662c 100644 --- a/docs/api-reference/next.config.js/basepath.md +++ b/docs/api-reference/next.config.js/basepath.md @@ -35,9 +35,7 @@ For example, using `/about` will automatically become `/docs/about` when `basePa export default function HomePage() { return ( <> - - About Page - + About Page > ) } diff --git a/docs/api-reference/next/link.md b/docs/api-reference/next/link.md index fa3a74405accdb..c8261e651f20b3 100644 --- a/docs/api-reference/next/link.md +++ b/docs/api-reference/next/link.md @@ -31,19 +31,13 @@ function Home() { return (
) @@ -56,6 +50,7 @@ export default Home - `href` - The path or URL to navigate to. This is the only required prop. It can also be an object, see [example here](/docs/api-reference/next/link.md#with-url-object) - `as` - Optional decorator for the path that will be shown in the browser URL bar. Before Next.js 9.5.3 this was used for dynamic routes, check our [previous docs](https://nextjs.org/docs/tag/v9.5.2/api-reference/next/link#dynamic-routes) to see how it worked. Note: when this path differs from the one provided in `href` the previous `href`/`as` behavior is used as shown in the [previous docs](https://nextjs.org/docs/tag/v9.5.2/api-reference/next/link#dynamic-routes). +- [`legacyBehavior`](#if-the-child-is-a-tag) - Changes behavior so that child must be ``. Defaults to `false`. - [`passHref`](#if-the-child-is-a-custom-component-that-wraps-an-a-tag) - Forces `Link` to send the `href` property to its child. Defaults to `false` - `prefetch` - Prefetch the page in the background. Defaults to `true`. Any `` that is in the viewport (initially or through scroll) will be preloaded. Prefetch can be disabled by passing `prefetch={false}`. When `prefetch` is set to `false`, prefetching will still occur on hover. Pages using [Static Generation](/docs/basic-features/data-fetching/get-static-props.md) will preload `JSON` files with the data for faster page transitions. Prefetching is only enabled in production. - [`replace`](#replace-the-url-instead-of-push) - Replace the current `history` state instead of adding a new url into the stack. Defaults to `false` @@ -78,7 +73,7 @@ function Posts({ posts }) { {posts.map((post) => (Count: {count}
- - one - - two - + one two ) } diff --git a/docs/migrating/from-gatsby.md b/docs/migrating/from-gatsby.md index d8388b283c75f5..98031267bc2ffb 100644 --- a/docs/migrating/from-gatsby.md +++ b/docs/migrating/from-gatsby.md @@ -78,15 +78,11 @@ export default function Home() { import Link from 'next/link' export default function Home() { - return ( - - blog - - ) + return blog } ``` -Update any import statements, switch `to` to `href`, and add an `` tag as a child of the element. +Update any import statements, switch `to` to `href`. ## Data Fetching diff --git a/docs/migrating/from-react-router.md b/docs/migrating/from-react-router.md index a81482f5e1ec3d..1174eaa5ed3c9a 100644 --- a/docs/migrating/from-react-router.md +++ b/docs/migrating/from-react-router.md @@ -34,7 +34,7 @@ import Link from 'next/link' export default function App() { return ( - About + About ) } diff --git a/docs/routing/dynamic-routes.md b/docs/routing/dynamic-routes.md index 9f0b7f66517f4b..87c02e856791de 100644 --- a/docs/routing/dynamic-routes.md +++ b/docs/routing/dynamic-routes.md @@ -63,18 +63,14 @@ function Home() { return (/blog/[author]
{JSON.stringify(params)}
{Date.now()}
- - /blog/tim + + /blog/tim/dynamic-no-gen-params
{JSON.stringify(params)}
- - /dynamic-no-gen-params/second + + /dynamic-no-gen-params/secondOther Page
- - To Page + + To Page > ) diff --git a/test/e2e/app-dir/app/app/template/clientcomponent/page.js b/test/e2e/app-dir/app/app/template/clientcomponent/page.js index 89378c7e29f176..4c9988bb9b33bf 100644 --- a/test/e2e/app-dir/app/app/template/clientcomponent/page.js +++ b/test/e2e/app-dir/app/app/template/clientcomponent/page.js @@ -4,8 +4,8 @@ export default function Page() { return ( <>Page
- - To Other + + To Other > ) diff --git a/test/e2e/app-dir/app/app/template/servercomponent/other/page.js b/test/e2e/app-dir/app/app/template/servercomponent/other/page.js index 2ed3a0fa15cef9..b9892154b6d4e8 100644 --- a/test/e2e/app-dir/app/app/template/servercomponent/other/page.js +++ b/test/e2e/app-dir/app/app/template/servercomponent/other/page.js @@ -3,8 +3,8 @@ export default function Page() { return ( <>Other Page
- - To Page + + To Page > ) diff --git a/test/e2e/app-dir/app/app/template/servercomponent/page.js b/test/e2e/app-dir/app/app/template/servercomponent/page.js index 27a7097ccd650c..bb83fba1ea7faa 100644 --- a/test/e2e/app-dir/app/app/template/servercomponent/page.js +++ b/test/e2e/app-dir/app/app/template/servercomponent/page.js @@ -4,8 +4,8 @@ export default function Page() { return ( <>Page
- - To Other + + To Other > ) diff --git a/test/e2e/app-dir/app/app/with-id/page.js b/test/e2e/app-dir/app/app/with-id/page.js index 07beecc4203fa3..afaab4d7d4aa01 100644 --- a/test/e2e/app-dir/app/app/with-id/page.js +++ b/test/e2e/app-dir/app/app/with-id/page.js @@ -5,8 +5,8 @@ export default function Page() { return ( <>- - To a with trailing slash + + To a with trailing slash
> diff --git a/test/e2e/app-dir/rsc-basic/app/next-api/link/page.js b/test/e2e/app-dir/rsc-basic/app/next-api/link/page.js index 13a9616be5e617..6f6893b2c31def 100644 --- a/test/e2e/app-dir/rsc-basic/app/next-api/link/page.js +++ b/test/e2e/app-dir/rsc-basic/app/next-api/link/page.js @@ -8,8 +8,8 @@ export default function LinkPage({ searchParams }) { <>- - To a with trailing slash + + To a with trailing slash
> diff --git a/test/e2e/basepath/pages/absolute-url-basepath.js b/test/e2e/basepath/pages/absolute-url-basepath.js index 2eb79686863cb6..09e8e607e18716 100644 --- a/test/e2e/basepath/pages/absolute-url-basepath.js +++ b/test/e2e/basepath/pages/absolute-url-basepath.js @@ -13,11 +13,12 @@ export default function Page({ port }) { const router = useRouter() return ( <> - - - http://localhost:{port} - {router.basePath}/something-else - + + http://localhost:{port} + {router.basePath}/something-else > ) diff --git a/test/e2e/basepath/pages/absolute-url-no-basepath.js b/test/e2e/basepath/pages/absolute-url-no-basepath.js index fb91bedaab51b1..fe56f971533ef5 100644 --- a/test/e2e/basepath/pages/absolute-url-no-basepath.js +++ b/test/e2e/basepath/pages/absolute-url-no-basepath.js @@ -11,8 +11,11 @@ export async function getServerSideProps({ query: { port } }) { export default function Page({ port }) { return ( <> - - http://localhost:{port}/rewrite-no-basepath + + http://localhost:{port}/rewrite-no-basepath > ) diff --git a/test/e2e/basepath/pages/absolute-url.js b/test/e2e/basepath/pages/absolute-url.js index 9d3c45efa7d308..2ff305be03b14c 100644 --- a/test/e2e/basepath/pages/absolute-url.js +++ b/test/e2e/basepath/pages/absolute-url.js @@ -4,12 +4,12 @@ import Link from 'next/link' export default function Page() { return ( <> - - https://vercel.com/ + + https://vercel.com/{JSON.stringify(query)}
{pathname}
{asPath}
- - to /hello + + to /hello > ) diff --git a/test/e2e/basepath/pages/invalid-manual-basepath.js b/test/e2e/basepath/pages/invalid-manual-basepath.js index 3fe46a8b4e480f..df7b075e3c0398 100644 --- a/test/e2e/basepath/pages/invalid-manual-basepath.js +++ b/test/e2e/basepath/pages/invalid-manual-basepath.js @@ -3,10 +3,8 @@ import { useRouter } from 'next/router' const Page = () => ( <> - - -{props.slug}
- - {props.now} + + {props.now} > ) diff --git a/test/e2e/getserversideprops/app/pages/another/index.js b/test/e2e/getserversideprops/app/pages/another/index.js index d582273fc39243..52b70952ffff98 100644 --- a/test/e2e/getserversideprops/app/pages/another/index.js +++ b/test/e2e/getserversideprops/app/pages/another/index.js @@ -19,12 +19,12 @@ export default ({ world, time }) => ( <>hello {world}
time: {time} - - to home + + to homePost: {post}
Comment: {comment}
time: {time} - - to home + + to home > ) diff --git a/test/e2e/getserversideprops/app/pages/blog/[post]/index.js b/test/e2e/getserversideprops/app/pages/blog/[post]/index.js index 00d0a1288432a6..c1d8ab5be45967 100644 --- a/test/e2e/getserversideprops/app/pages/blog/[post]/index.js +++ b/test/e2e/getserversideprops/app/pages/blog/[post]/index.js @@ -36,8 +36,8 @@ export default ({ post, time, params, appProps, resolvedUrl }) => {Posts: {JSON.stringify(slugs)}
time: {time} - - to home + + to home > ) diff --git a/test/e2e/getserversideprops/app/pages/catchall/[...path].js b/test/e2e/getserversideprops/app/pages/catchall/[...path].js index cfbd2e1c3019ce..6da108a268bda2 100644 --- a/test/e2e/getserversideprops/app/pages/catchall/[...path].js +++ b/test/e2e/getserversideprops/app/pages/catchall/[...path].js @@ -21,12 +21,12 @@ export default ({ world, time, params, random }) => {hello {world}
time: {time} - - to home + + to homehello {world}
time: {time} - - to non-json + + to non-json{JSON.stringify(router.query)}
{router.pathname}
{router.asPath}
- - to / + + to /{JSON.stringify(router.query)}
{router.pathname}
{router.asPath}
- - to / + + to /a slow page
hit: {count}
- - to home + + to homeUser: {user}
time: {time} - - to home + + to home > ) diff --git a/test/e2e/i18n-data-fetching-redirect/app/pages/index.js b/test/e2e/i18n-data-fetching-redirect/app/pages/index.js index a63a1bbebf1df7..776c448bea6cf1 100644 --- a/test/e2e/i18n-data-fetching-redirect/app/pages/index.js +++ b/test/e2e/i18n-data-fetching-redirect/app/pages/index.js @@ -3,38 +3,40 @@ import Link from 'next/link' export default function Component() { return ( <> - - to /gssp-redirect/en" + + to /gssp-redirect/en" - - to /gssp-redirect/sv" + + to /gssp-redirect/sv" - - to /gssp-redirect/from-ctx + + to /gssp-redirect/from-ctx - - to /gsp-blocking-redirect/en" + + to /gsp-blocking-redirect/en" - - to /gsp-blocking-redirect/sv" + + to /gsp-blocking-redirect/sv" - - - to /gsp-blocking-redirect/from-ctx - + + to /gsp-blocking-redirect/from-ctx - - to /gsp-fallback-redirect/en" + + to /gsp-fallback-redirect/en" - - to /gsp-fallback-redirect/sv" + + to /gsp-fallback-redirect/sv" - - - to /gsp-fallback-redirect/from-ctx - + + to /gsp-fallback-redirect/from-ctx > ) diff --git a/test/e2e/link-with-api-rewrite/app/pages/index.js b/test/e2e/link-with-api-rewrite/app/pages/index.js index ae6a4e05c3a7fd..a5324fc832aa63 100644 --- a/test/e2e/link-with-api-rewrite/app/pages/index.js +++ b/test/e2e/link-with-api-rewrite/app/pages/index.js @@ -3,11 +3,11 @@ import Link from 'next/link' export default function Page() { return (This should not run the middleware
{JSON.stringify(props)}
- - to /another-middleware + + to /another-middlewareroot page
{JSON.stringify(props)}
- - to /another-middleware + + to /another-middlewareHome Page
- - Redirect me to a new version of a page + + Redirect me to a new version of a page - - Redirect me to an external site + + Redirect me to an external site - - Redirect me with URL params intact - + Redirect me with URL params intact - Redirect me to Google (with no body response) + Redirect me to Google (with no body response) - Redirect me to Google (with no stream response) + Redirect me to Google (with no stream response) - - Redirect me alot (chained requests) - + Redirect me alot (chained requests) - - Redirect me alot (infinite loop) - + Redirect me alot (infinite loop) - - Redirect me to api with locale + + Redirect me to api with locale - - - Redirect me to a redirecting page of new version of page - + + Redirect me to a redirecting page of new version of pageHello {message}
- - Stream a response - + Stream a response - - Stream a long response - - - Test streaming after response ends - + Stream a long response + Test streaming after response ends - Attempt to add a header after stream ends + Attempt to add a header after stream ends - Redirect to Google and attempt to stream after + Redirect to Google and attempt to stream after - - Respond with a header - + Respond with a header - Respond with 2 headers (nested middleware effect) + Respond with 2 headers (nested middleware effect) - - Respond with body, end, set a header - + Respond with body, end, set a header - Respond with body, end, send another body + Respond with body, end, send another body - - Respond with body - + Respond with body - - Redirect and then send a body - + Redirect and then send a body - - Send React component as a body - + Send React component as a body - - Stream React component - + Stream React component - - 404 - + 404{JSON.stringify(props)}
- - to /fallback-true-blog/first?hello=world + + to /fallback-true-blog/first?hello=worldHome Page
- - A/B test homepage - + A/B test homepage - - Rewrite me to about + + Rewrite me to about - - - Rewrite me to beforeFiles Rewrite - + + Rewrite me to beforeFiles Rewrite - - - Rewrite me to afterFiles Rewrite - + + Rewrite me to afterFiles Rewrite - - Rewrite me to Vercel - + Rewrite me to Vercel - Redirect me to Vercel (but with double reroutes) + Redirect me to Vercel (but with double reroutes) - - Rewrite me without a hard navigation + + Rewrite me without a hard navigation - - Rewrite me to external site + + Rewrite me to external site - - Rewrite me to internal path + + Rewrite me to internal path - - normal SSG link + + normal SSG link - - Throw on data + + Throw on datahello {world}
time: {time} - - to home + + to homePost: {post}
Comment: {comment}
time: {time} - - to home + + to home > ) diff --git a/test/e2e/prerender/pages/blog/[post]/index.js b/test/e2e/prerender/pages/blog/[post]/index.js index 6f0e3c0ea101e2..85456078750614 100644 --- a/test/e2e/prerender/pages/blog/[post]/index.js +++ b/test/e2e/prerender/pages/blog/[post]/index.js @@ -53,8 +53,8 @@ export default ({ post, time, params }) => { time: {time}Posts: {JSON.stringify(slugs)}
time: {time} - - to home + + to home > ) diff --git a/test/e2e/prerender/pages/catchall-explicit/[...slug].js b/test/e2e/prerender/pages/catchall-explicit/[...slug].js index 103b5650af58b2..6a8448d9756928 100644 --- a/test/e2e/prerender/pages/catchall-explicit/[...slug].js +++ b/test/e2e/prerender/pages/catchall-explicit/[...slug].js @@ -35,8 +35,8 @@ export default function Page({ slug, time }) { <>Hi {slug.join(' ')}
time: {time}
- - to home + + to home > ) diff --git a/test/e2e/prerender/pages/catchall-optional/[[...slug]].js b/test/e2e/prerender/pages/catchall-optional/[[...slug]].js index 2e613944725c99..a3342e4684a3c4 100644 --- a/test/e2e/prerender/pages/catchall-optional/[[...slug]].js +++ b/test/e2e/prerender/pages/catchall-optional/[[...slug]].js @@ -21,8 +21,8 @@ export default ({ slug }) => { return ( <>Catch all: [{slug.join(', ')}]
- - to home + + to home > ) diff --git a/test/e2e/prerender/pages/default-revalidate.js b/test/e2e/prerender/pages/default-revalidate.js index 68570ca0ba7233..a044bc159750d3 100644 --- a/test/e2e/prerender/pages/default-revalidate.js +++ b/test/e2e/prerender/pages/default-revalidate.js @@ -13,12 +13,12 @@ export default ({ world, time }) => ( <>hello {world}
time: {time} - - to home + + to homeHi {slug}!
{' '} - - to home + + to home > ) diff --git a/test/e2e/prerender/pages/fallback-only/[slug].js b/test/e2e/prerender/pages/fallback-only/[slug].js index dbb44ed06ce693..57172c74ae22b9 100644 --- a/test/e2e/prerender/pages/fallback-only/[slug].js +++ b/test/e2e/prerender/pages/fallback-only/[slug].js @@ -35,8 +35,8 @@ export default ({ post, time, params }) => { time: {time}hello {world}
time: {time} - - to non-json + + to non-jsonlots of data returned
- - to home + + to homeUser: {user}
time: {time} - - to home + + to home > ) diff --git a/test/e2e/reload-scroll-backforward-restoration/pages/[id].js b/test/e2e/reload-scroll-backforward-restoration/pages/[id].js index 3076a7fce7935e..938a4a43f669e9 100644 --- a/test/e2e/reload-scroll-backforward-restoration/pages/[id].js +++ b/test/e2e/reload-scroll-backforward-restoration/pages/[id].js @@ -21,17 +21,16 @@ const Page = ({ id }) => { }} />{ready ? 'routeChangeComplete' : 'loading'}
- - - next page - + + next pageanother page
- - to index + + to indexblog page
- - to index + + to indexindex page
- - to another + + to anotherhello nextjs
- - home - + homehello world
isAmp: {isAmp ? 'yes' : 'false'}
- - link to module + + link to module > ) @@ -51,8 +51,8 @@ describe('Type module interop', () => { export default function Modules() { return ( <> - - link to home + + link to homeNo AMP for me...
- - To AMP page! + + To AMP page!- - go home + + go home