I just started learning NextJS 13 App route, I’m a bit confused about URLs.
structure folder:
app
products
[slug]
page.tsx
components
ProductCard.tsx
example:
// ProductCard.tsx
return (
<div>
<Link href={`/products/${prod.slug}`} />
</div>
)
when click to Link then url is 'localhost:3000/products/car'
i want url is 'localhost:3000/car'
help me!
2
Answers
As per looking at your question, you want your url to be
And this is happening
So as per what you need is
href={/${prod.slug}}
So you will get the url like
https://localhost:3000/whatever the sug contains
Edit the srtucture so you don’t get 404:
and edit your ProductCard.tsx: