Next.js Discord

Discord Forum

How to navigate using relative hrefs?

Unanswered
Australian Freshwater Crocodile posted this in #help-forum
Open in Discord
Australian Freshwater CrocodileOP
Adding a link like
<Link href={"./potato"} />


Navigates to /potato instead of my/current/route/potato. What am i missing?

4 Replies

@Australian Freshwater Crocodile Adding a link like <Link href={"./potato"} /> Navigates to `/potato` instead of `my/current/route/potato`. What am i missing?
if you change it to route/hello you would be redirected to my/current/route/hello. So you need to replicate the last segment and give the next segment
Australian Freshwater CrocodileOP
I know. How can i avoid that, so that the path is relative?
I want to have a hardcoded ./relative/path
Sun bear
You are currently on example.com/starting/route

<Link href="/hello">Hello</Link>
// goes to example.com/hello


<Link href="hello">Hello</Link>
// goes to example.com/starting/route/hello