Files
81f5ed7aa2 Fix: Router.query contains _next when using middleware with dynamic routes (#48753)
Fixes: #43598

This was a tricky one to find! Not sure why more people aren't
complaining about this issue, was super annoying in my use case since
links had the wrong URL.

## What?
This issue only occurred when basepath was defined and middleware and
dynamic pages are being used.
Example from the reproduction repo mentioned in the issue tagged:
<img width="686" alt="Screenshot 2023-04-23 at 9 32 55 PM"
src="https://user-images.githubusercontent.com/11258286/233850968-e14f6b49-858b-410e-b8f9-93c90447090a.png">


## Why?
`nextConfig` wasn't passed to `getNextPathnameInfo` function, hence the
basePath wasn't removed from a intermediate variable and that trickled
down to cause this issue.

Added test case based on the issue reproduction repo

---------

Co-authored-by: Jimmy Lai <[email protected]>
2023-05-09 12:49:27 +02:00

36 lines
643 B
JavaScript

import Link from 'next/link'
import { useRouter } from 'next/router'
const Index = ({ value }) => {
const router = useRouter()
return (
<section>
<h1>{value}</h1>
<p id="router-path">
<strong>{router.query.path}</strong>
</p>
<Link href="/another-page" id="linkelement">
Link to another page
</Link>
</section>
)
}
export async function getStaticPaths() {
return {
paths: [{ params: { path: 'another-page', pages: null } }],
fallback: true,
}
}
export async function getStaticProps() {
return {
props: {
value: 'Hello',
},
}
}
export default Index