App Directory: MDX & Link doesn't work properly with relative links #50183
Labels
area: app
App directory (appDir: true)
bug
Issue was opened via the bug report template.
locked
Markdown (MDX)
Related to Markdown with Next.js.
Navigation
Related to Next.js linking (e.g., <Link>) and navigation.
Verify canary release
Provide environment information
Which area(s) of Next.js are affected? (leave empty if unsure)
App directory (appDir: true), MDX (@next/mdx), Routing (next/router, next/navigation, next/link)
Link to the code that reproduces this issue or a replay of the bug
https://codesandbox.io/p/sandbox/nextjs-relative-links-bug-7wgdly
To Reproduce
I copied the code from next.js/examples/app-dir-mdx. the only additional change I made was:
app/blog/test/page.mdx
<a>
to usenext/link
Describe the Bug
in the
.mdx
pages, I have added relative links to one of the other pages in the folder like below:[next page](./plain-markdown)
I added the customization for the anchor tag in
mdx-components.tsx
. But after the customization, the links are not being redirected properly.http://localhost:3001/blog/test
, i'm being redirected tohttp://localhost:3001/test
.But what I noticed is that the url in the anchor tag href attribute is different when using app directory:
<a href="/blog/plain-markdown">
<a href="./plain-markdown">
Please note that this isue is caused on when I override the default
<a>
element to use the next/link component. with the default<`> element, it works fine.Expected Behavior
clicking on
http://localhost:3001/blog/test
should take me to the respective pageWhich browser are you using? (if relevant)
Microsoft Edge Version 113.0.1774.42 (Official build) (64-bit)
How are you deploying your application? (if relevant)
No response
The text was updated successfully, but these errors were encountered: