Unverified Commit d397832e authored by kevinmitch14's avatar kevinmitch14 Committed by GitHub

Docs: update link.mdx (#61508)

Updated paths in relation to `<Link />` and middleware rewrites. Feel
free to leave suggestions if needed, this has always confused me a
little bit.

**Old Version**:
For example, if you have a Dynamic Route like `/dashboard/[user]` that
you want to present differently via middleware, you would write: `<Link
href={{ pathname: '/dashboard/authed/[user]', query: { user: username }
}} as="/dashboard/[user]">Profile</Link>`.

The `as` prop should be the URL we want to display while href/pathname
is the actual path. So if we want to present something differently via
middleware, we would do so via `as`. In the example above we want to
display `/dashboard/[user]` differently but we use
`as='/dashboard/[user]'`.
parent e71046b6
...@@ -484,7 +484,7 @@ import useIsAuthed from './hooks/useIsAuthed' ...@@ -484,7 +484,7 @@ import useIsAuthed from './hooks/useIsAuthed'
export default function Page() { export default function Page() {
const isAuthed = useIsAuthed() const isAuthed = useIsAuthed()
const path = isAuthed ? '/auth/dashboard' : '/dashboard' const path = isAuthed ? '/auth/dashboard' : '/public/dashboard'
return ( return (
<Link as="/dashboard" href={path}> <Link as="/dashboard" href={path}>
Dashboard Dashboard
...@@ -495,7 +495,7 @@ export default function Page() { ...@@ -495,7 +495,7 @@ export default function Page() {
<PagesOnly> <PagesOnly>
> **Good to know**: If you're using [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes), you'll need to adapt your `as` and `href` props. For example, if you have a Dynamic Route like `/dashboard/[user]` that you want to present differently via middleware, you would write: `<Link href={{ pathname: '/dashboard/authed/[user]', query: { user: username } }} as="/dashboard/[user]">Profile</Link>`. > **Good to know**: If you're using [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes), you'll need to adapt your `as` and `href` props. For example, if you have a Dynamic Route like `/dashboard/authed/[user]` that you want to present differently via middleware, you would write: `<Link href={{ pathname: '/dashboard/authed/[user]', query: { user: username } }} as="/dashboard/[user]">Profile</Link>`.
</PagesOnly> </PagesOnly>
......
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