Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
b1ef76df
Unverified
Commit
b1ef76df
authored
Aug 07, 2020
by
JJ Kasper
Committed by
GitHub
Aug 07, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix asPath normalizing for non-dynamic pages (#15960)
parent
db69e474
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
7 deletions
+27
-7
next-serverless-loader.ts
...ages/next/build/webpack/loaders/next-serverless-loader.ts
+12
-6
about.js
test/integration/dynamic-optional-routing/pages/about.js
+7
-1
server.js
test/integration/dynamic-optional-routing/server.js
+2
-0
index.test.js
test/integration/dynamic-optional-routing/test/index.test.js
+6
-0
No files found.
packages/next/build/webpack/loaders/next-serverless-loader.ts
View file @
b1ef76df
...
@@ -439,14 +439,20 @@ const nextServerlessLoader: loader.Loader = function () {
...
@@ -439,14 +439,20 @@ const nextServerlessLoader: loader.Loader = function () {
// make sure to normalize req.url on Vercel to strip dynamic params
// make sure to normalize req.url on Vercel to strip dynamic params
// from the query which are added during routing
// from the query which are added during routing
if (trustQuery) {
${
const _parsedUrl = parseUrl(req.url, true)
pageIsDynamicRoute
delete _parsedUrl.search
?
`
if (trustQuery) {
const _parsedUrl = parseUrl(req.url, true)
delete _parsedUrl.search
for (const param of Object.keys(defaultRouteRegex.groups)) {
for (const param of Object.keys(defaultRouteRegex.groups)) {
delete _parsedUrl.query[param]
delete _parsedUrl.query[param]
}
req.url = formatUrl(_parsedUrl)
}
}
req.url = formatUrl(_parsedUrl)
`
:
''
}
}
const isFallback = parsedUrl.query.__nextFallback
const isFallback = parsedUrl.query.__nextFallback
...
...
test/integration/dynamic-optional-routing/pages/about.js
View file @
b1ef76df
export
default
function
Page
(
props
)
{
export
default
function
Page
(
props
)
{
return
<
div
>
about
<
/div
>
return
<
div
id
=
"content"
>
about
<
/div
>
}
export
const
getServerSideProps
=
()
=>
{
return
{
props
:
{},
}
}
}
test/integration/dynamic-optional-routing/server.js
View file @
b1ef76df
...
@@ -16,6 +16,8 @@ const server = http.createServer((req, res) => {
...
@@ -16,6 +16,8 @@ const server = http.createServer((req, res) => {
const
{
pathname
}
=
url
.
parse
(
req
.
url
)
const
{
pathname
}
=
url
.
parse
(
req
.
url
)
switch
(
pathname
)
{
switch
(
pathname
)
{
case
'/about'
:
return
render
(
'/about.js'
)
case
'/api/post'
:
case
'/api/post'
:
case
'/api/post/hello'
:
case
'/api/post/hello'
:
case
'/api/post/hello/world'
:
{
case
'/api/post/hello/world'
:
{
...
...
test/integration/dynamic-optional-routing/test/index.test.js
View file @
b1ef76df
...
@@ -370,6 +370,12 @@ describe('Dynamic Optional Routing', () => {
...
@@ -370,6 +370,12 @@ describe('Dynamic Optional Routing', () => {
}).
then
((
res
)
=>
res
.
text
())
}).
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
()
=>
{
it
(
'should render top level optional catch-all root'
,
async
()
=>
{
const
html
=
await
render
(
'/'
,
{
optionalName
:
''
})
const
html
=
await
render
(
'/'
,
{
optionalName
:
''
})
const
$
=
cheerio
.
load
(
html
)
const
$
=
cheerio
.
load
(
html
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment