Both links work exactly the same, do we really need to use the as, can't we use just the href?
import Link from 'next/link'
export default function () {
return (<>
<Link href="/someroute">
<a>WithOUT as</a>
</Link>
<br />
<br />
<Link href="/[param]" as="/someroute">
<a>With as</a>
</Link>
</>
)
}
"as" is used to have a nicer url. for example, since you are in a dynamic route, that
paramcan be something very crazy, maybe a mongodb id or any hash valueFrom early docs
So when next.js navigates, to decide which page to render, it will look at the
hrefbut to decide which url to show the user, it will look at theaswhen "as" is helpful
Let's say you have a
DynamicPostComponentand you are passingpostpropInside this component, you would tell next.js where to go in pages directory. so you use
hrefnow inside the page you need to read the
idof blog so that you have to fetch the post to show the user. for this you useasYour Link compnent will look like this
asis removed after v10. https://nextjs.org/blog/next-10