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
4006812b
Unverified
Commit
4006812b
authored
Nov 21, 2022
by
JJ Kasper
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update experimental skipTrailingSlashRedirect handling
parent
be75d092
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
56 additions
and
1 deletion
+56
-1
webpack-config.ts
packages/next/build/webpack-config.ts
+3
-0
normalize-trailing-slash.ts
packages/next/client/normalize-trailing-slash.ts
+1
-1
index.js
test/e2e/skip-trailing-slash-redirect/app/pages/index.js
+4
-0
index.test.ts
test/e2e/skip-trailing-slash-redirect/index.test.ts
+48
-0
No files found.
packages/next/build/webpack-config.ts
View file @
4006812b
...
@@ -161,6 +161,9 @@ export function getDefineEnv({
...
@@ -161,6 +161,9 @@ export function getDefineEnv({
'process.env.__NEXT_ALLOW_MIDDLEWARE_RESPONSE_BODY'
:
JSON
.
stringify
(
'process.env.__NEXT_ALLOW_MIDDLEWARE_RESPONSE_BODY'
:
JSON
.
stringify
(
config
.
experimental
.
allowMiddlewareResponseBody
config
.
experimental
.
allowMiddlewareResponseBody
),
),
'process.env.__NEXT_MANUAL_TRAILING_SLASH'
:
JSON
.
stringify
(
config
.
experimental
?.
skipTrailingSlashRedirect
),
'process.env.__NEXT_CROSS_ORIGIN'
:
JSON
.
stringify
(
config
.
crossOrigin
),
'process.env.__NEXT_CROSS_ORIGIN'
:
JSON
.
stringify
(
config
.
crossOrigin
),
'process.browser'
:
JSON
.
stringify
(
isClient
),
'process.browser'
:
JSON
.
stringify
(
isClient
),
'process.env.__NEXT_TEST_MODE'
:
JSON
.
stringify
(
'process.env.__NEXT_TEST_MODE'
:
JSON
.
stringify
(
...
...
packages/next/client/normalize-trailing-slash.ts
View file @
4006812b
...
@@ -6,7 +6,7 @@ import { parsePath } from '../shared/lib/router/utils/parse-path'
...
@@ -6,7 +6,7 @@ import { parsePath } from '../shared/lib/router/utils/parse-path'
* in `next.config.js`.
* in `next.config.js`.
*/
*/
export
const
normalizePathTrailingSlash
=
(
path
:
string
)
=>
{
export
const
normalizePathTrailingSlash
=
(
path
:
string
)
=>
{
if
(
!
path
.
startsWith
(
'/'
))
{
if
(
!
path
.
startsWith
(
'/'
)
||
process
.
env
.
__NEXT_MANUAL_TRAILING_SLASH
)
{
return
path
return
path
}
}
...
...
test/e2e/skip-trailing-slash-redirect/app/pages/index.js
View file @
4006812b
...
@@ -8,6 +8,10 @@ export default function Page(props) {
...
@@ -8,6 +8,10 @@ export default function Page(props) {
to
another
to
another
<
/Link
>
<
/Link
>
<
br
/>
<
br
/>
<
Link
href
=
"/another/"
id
=
"to-another-with-slash"
>
to
another
<
/Link
>
<
br
/>
<
Link
href
=
"/blog/first"
id
=
"to-blog-first"
>
<
Link
href
=
"/blog/first"
id
=
"to-blog-first"
>
to
/
blog
/
first
to
/
blog
/
first
<
/Link
>
<
/Link
>
...
...
test/e2e/skip-trailing-slash-redirect/index.test.ts
View file @
4006812b
...
@@ -158,6 +158,54 @@ describe('skip-trailing-slash-redirect', () => {
...
@@ -158,6 +158,54 @@ describe('skip-trailing-slash-redirect', () => {
expect
(
await
res
.
text
()).
toContain
(
'another page'
)
expect
(
await
res
.
text
()).
toContain
(
'another page'
)
})
})
it
(
'should not apply trailing slash to links on client'
,
async
()
=>
{
const
browser
=
await
webdriver
(
next
.
url
,
'/'
)
await
browser
.
eval
(
'window.beforeNav = 1'
)
expect
(
new
URL
(
await
browser
.
elementByCss
(
'#to-another'
).
getAttribute
(
'href'
),
'http://n'
).
pathname
).
toBe
(
'/another'
)
await
browser
.
elementByCss
(
'#to-another'
).
click
()
await
browser
.
waitForElementByCss
(
'#another'
)
expect
(
await
browser
.
eval
(
'window.location.pathname'
)).
toBe
(
'/another'
)
await
browser
.
back
().
waitForElementByCss
(
'#to-another'
)
expect
(
new
URL
(
await
browser
.
elementByCss
(
'#to-another-with-slash'
)
.
getAttribute
(
'href'
),
'http://n'
).
pathname
).
toBe
(
'/another/'
)
await
browser
.
elementByCss
(
'#to-another-with-slash'
).
click
()
await
browser
.
waitForElementByCss
(
'#another'
)
expect
(
await
browser
.
eval
(
'window.location.pathname'
)).
toBe
(
'/another/'
)
await
browser
.
back
().
waitForElementByCss
(
'#to-another'
)
expect
(
await
browser
.
eval
(
'window.beforeNav'
)).
toBe
(
1
)
})
it
(
'should not apply trailing slash on load on client'
,
async
()
=>
{
let
browser
=
await
webdriver
(
next
.
url
,
'/another'
)
await
check
(()
=>
browser
.
eval
(
'next.router.isReady ? "yes": "no"'
),
'yes'
)
expect
(
await
browser
.
eval
(
'location.pathname'
)).
toBe
(
'/another'
)
browser
=
await
webdriver
(
next
.
url
,
'/another/'
)
await
check
(()
=>
browser
.
eval
(
'next.router.isReady ? "yes": "no"'
),
'yes'
)
expect
(
await
browser
.
eval
(
'location.pathname'
)).
toBe
(
'/another/'
)
})
it
(
'should not apply trailing slash redirect (with slash)'
,
async
()
=>
{
it
(
'should not apply trailing slash redirect (with slash)'
,
async
()
=>
{
const
res
=
await
fetchViaHTTP
(
next
.
url
,
'/another/'
,
undefined
,
{
const
res
=
await
fetchViaHTTP
(
next
.
url
,
'/another/'
,
undefined
,
{
redirect
:
'manual'
,
redirect
:
'manual'
,
...
...
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