Unverified Commit b1ef76df authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Fix asPath normalizing for non-dynamic pages (#15960)

parent db69e474
......@@ -439,14 +439,20 @@ const nextServerlessLoader: loader.Loader = function () {
// make sure to normalize req.url on Vercel to strip dynamic params
// from the query which are added during routing
if (trustQuery) {
const _parsedUrl = parseUrl(req.url, true)
delete _parsedUrl.search
${
pageIsDynamicRoute
? `
if (trustQuery) {
const _parsedUrl = parseUrl(req.url, true)
delete _parsedUrl.search
for (const param of Object.keys(defaultRouteRegex.groups)) {
delete _parsedUrl.query[param]
for (const param of Object.keys(defaultRouteRegex.groups)) {
delete _parsedUrl.query[param]
}
req.url = formatUrl(_parsedUrl)
}
req.url = formatUrl(_parsedUrl)
`
: ''
}
const isFallback = parsedUrl.query.__nextFallback
......
export default function Page(props) {
return <div>about</div>
return <div id="content">about</div>
}
export const getServerSideProps = () => {
return {
props: {},
}
}
......@@ -16,6 +16,8 @@ const server = http.createServer((req, res) => {
const { pathname } = url.parse(req.url)
switch (pathname) {
case '/about':
return render('/about.js')
case '/api/post':
case '/api/post/hello':
case '/api/post/hello/world': {
......
......@@ -370,6 +370,12 @@ describe('Dynamic Optional Routing', () => {
}).then((res) => res.text())
}
it('should render normal (non-dynamic) page', async () => {
const html = await render('/about')
const $ = cheerio.load(html)
expect($('#content').text()).toBe('about')
})
it('should render top level optional catch-all root', async () => {
const html = await render('/', { optionalName: '' })
const $ = cheerio.load(html)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment