Skip to content

Commit c10bf51

Browse files
authoredOct 20, 2022
fix(gatsby): Set trailingSlash default to "always" (#36798)
1 parent 90f9ab4 commit c10bf51

File tree

36 files changed

+207
-473
lines changed

36 files changed

+207
-473
lines changed
 

‎e2e-tests/development-runtime/cypress/integration/functionality/client-only-paths.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
describe(`Client only paths`, () => {
22
const routes = [
33
{
4-
path: `/client-only-paths`,
4+
path: `/client-only-paths/`,
55
marker: `index`,
66
label: `Index route`,
77
},
88
{
9-
path: `/client-only-paths/page/profile`,
9+
path: `/client-only-paths/page/profile/`,
1010
marker: `profile`,
1111
label: `Dynamic route`,
1212
},
1313
{
14-
path: `/client-only-paths/not-found`,
14+
path: `/client-only-paths/not-found/`,
1515
marker: `NotFound`,
1616
label: `Default route (not found)`,
1717
},
1818
{
19-
path: `/client-only-paths/nested`,
19+
path: `/client-only-paths/nested/`,
2020
marker: `nested-page/index`,
2121
label: `Index route inside nested router`,
2222
},
2323
{
24-
path: `/client-only-paths/nested/foo`,
24+
path: `/client-only-paths/nested/foo/`,
2525
marker: `nested-page/foo`,
2626
label: `Dynamic route inside nested router`,
2727
},
2828
{
29-
path: `/client-only-paths/static`,
29+
path: `/client-only-paths/static/`,
3030
marker: `static-sibling`,
3131
label: `Static route that is a sibling to client only path`,
3232
},

‎e2e-tests/development-runtime/cypress/integration/functionality/query-data-caches.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function getExpectedCanonicalPath(config) {
7373
return `/query-data-caches/${config.slug}/${
7474
config.page === `client-only`
7575
? `:client-only`
76-
: `page-${config.page}${config.trailingSlash === false ? `` : `/`}`
76+
: `page-${config.page}/`
7777
}`
7878
}
7979

‎e2e-tests/development-runtime/cypress/integration/navigation/linking.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ describe(`navigation`, () => {
4646
cy.getTestElement(`subdir-link`)
4747
.click()
4848
.location(`pathname`)
49-
.should(`eq`, `/subdirectory/page-1`)
49+
.should(`eq`, `/subdirectory/page-1/`)
5050
})
5151

5252
it(`can navigate to a sibling page`, () => {
@@ -55,7 +55,7 @@ describe(`navigation`, () => {
5555
.getTestElement(`page-2-link`)
5656
.click()
5757
.location(`pathname`)
58-
.should(`eq`, `/subdirectory/page-2`)
58+
.should(`eq`, `/subdirectory/page-2/`)
5959
})
6060

6161
it(`can navigate to a parent page`, () => {
@@ -64,7 +64,7 @@ describe(`navigation`, () => {
6464
.getTestElement(`page-parent-link`)
6565
.click()
6666
.location(`pathname`)
67-
.should(`eq`, `/subdirectory`)
67+
.should(`eq`, `/subdirectory/`)
6868
})
6969

7070
it(`can navigate to a sibling page programatically`, () => {
@@ -73,7 +73,7 @@ describe(`navigation`, () => {
7373
.getTestElement(`page-2-button-link`)
7474
.click()
7575
.location(`pathname`)
76-
.should(`eq`, `/subdirectory/page-2`)
76+
.should(`eq`, `/subdirectory/page-2/`)
7777
})
7878
})
7979

‎e2e-tests/development-runtime/cypress/integration/navigation/redirect.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
const runTests = () => {
22
it(`should redirect page to index page when there is no such page`, () => {
3-
cy.visit(`/redirect-without-page`, {
3+
cy.visit(`/redirect-without-page/`, {
44
failOnStatusCode: false,
55
}).waitForRouteChange()
66

77
cy.location(`pathname`).should(`equal`, `/`)
88
})
99

1010
it(`should redirect page to index page even there is a such page`, () => {
11-
cy.visit(`/redirect`, {
11+
cy.visit(`/redirect/`, {
1212
failOnStatusCode: false,
1313
}).waitForRouteChange()
1414

@@ -29,17 +29,17 @@ const runTests = () => {
2929
}).waitForRouteChange()
3030

3131
cy.getTestElement(`redirect-two-anchor`).click().waitForRouteChange()
32-
cy.location(`pathname`).should(`equal`, `/redirect-search-hash`)
32+
cy.location(`pathname`).should(`equal`, `/redirect-search-hash/`)
3333
cy.location(`hash`).should(`equal`, `#anchor`)
3434
cy.location(`search`).should(`equal`, ``)
3535
})
3636

3737
it(`should support hash parameter on direct visit`, () => {
38-
cy.visit(`/redirect-two#anchor`, {
38+
cy.visit(`/redirect-two/#anchor`, {
3939
failOnStatusCode: false,
4040
}).waitForRouteChange()
4141

42-
cy.location(`pathname`).should(`equal`, `/redirect-search-hash`)
42+
cy.location(`pathname`).should(`equal`, `/redirect-search-hash/`)
4343
cy.location(`hash`).should(`equal`, `#anchor`)
4444
cy.location(`search`).should(`equal`, ``)
4545
})
@@ -50,17 +50,17 @@ const runTests = () => {
5050
}).waitForRouteChange()
5151

5252
cy.getTestElement(`redirect-two-search`).click().waitForRouteChange()
53-
cy.location(`pathname`).should(`equal`, `/redirect-search-hash`)
53+
cy.location(`pathname`).should(`equal`, `/redirect-search-hash/`)
5454
cy.location(`hash`).should(`equal`, ``)
5555
cy.location(`search`).should(`equal`, `?query_param=hello`)
5656
})
5757

5858
it(`should support search parameter on direct visit`, () => {
59-
cy.visit(`/redirect-two?query_param=hello`, {
59+
cy.visit(`/redirect-two/?query_param=hello`, {
6060
failOnStatusCode: false,
6161
}).waitForRouteChange()
6262

63-
cy.location(`pathname`).should(`equal`, `/redirect-search-hash`)
63+
cy.location(`pathname`).should(`equal`, `/redirect-search-hash/`)
6464
cy.location(`hash`).should(`equal`, ``)
6565
cy.location(`search`).should(`equal`, `?query_param=hello`)
6666
})
@@ -71,17 +71,17 @@ const runTests = () => {
7171
}).waitForRouteChange()
7272

7373
cy.getTestElement(`redirect-two-search-anchor`).click().waitForRouteChange()
74-
cy.location(`pathname`).should(`equal`, `/redirect-search-hash`)
74+
cy.location(`pathname`).should(`equal`, `/redirect-search-hash/`)
7575
cy.location(`hash`).should(`equal`, `#anchor`)
7676
cy.location(`search`).should(`equal`, `?query_param=hello`)
7777
})
7878

7979
it(`should support search & hash parameter on direct visit`, () => {
80-
cy.visit(`/redirect-two?query_param=hello#anchor`, {
80+
cy.visit(`/redirect-two/?query_param=hello#anchor`, {
8181
failOnStatusCode: false,
8282
}).waitForRouteChange()
8383

84-
cy.location(`pathname`).should(`equal`, `/redirect-search-hash`)
84+
cy.location(`pathname`).should(`equal`, `/redirect-search-hash/`)
8585
cy.location(`hash`).should(`equal`, `#anchor`)
8686
cy.location(`search`).should(`equal`, `?query_param=hello`)
8787
})

‎e2e-tests/development-runtime/gatsby-node.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -196,22 +196,22 @@ exports.createPages = async function createPages({
196196
})
197197

198198
createRedirect({
199-
fromPath: `/redirect-without-page`,
199+
fromPath: `/redirect-without-page/`,
200200
toPath: `/`,
201201
isPermanent: true,
202202
redirectInBrowser: true,
203203
})
204204

205205
createRedirect({
206-
fromPath: `/redirect`,
206+
fromPath: `/redirect/`,
207207
toPath: `/`,
208208
isPermanent: true,
209209
redirectInBrowser: true,
210210
})
211211

212212
createRedirect({
213-
fromPath: `/redirect-two`,
214-
toPath: `/redirect-search-hash`,
213+
fromPath: `/redirect-two/`,
214+
toPath: `/redirect-search-hash/`,
215215
isPermanent: true,
216216
redirectInBrowser: true,
217217
})

‎e2e-tests/development-runtime/src/pages/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,17 @@ const IndexPage = ({ data }) => (
4646
<Link to="/new-page" data-testid="hot-reloading-new-file">
4747
Created by hot-reloading/new-file.js
4848
</Link>
49-
<Link to="/redirect-two#anchor" data-testid="redirect-two-anchor">
49+
<Link to="/redirect-two/#anchor" data-testid="redirect-two-anchor">
5050
Go to redirect with hash
5151
</Link>
5252
<Link
53-
to="/redirect-two?query_param=hello"
53+
to="/redirect-two/?query_param=hello"
5454
data-testid="redirect-two-search"
5555
>
5656
Go to redirect with query param
5757
</Link>
5858
<Link
59-
to="/redirect-two?query_param=hello#anchor"
59+
to="/redirect-two/?query_param=hello#anchor"
6060
data-testid="redirect-two-search-anchor"
6161
>
6262
Go to redirect with query param and hash

‎e2e-tests/path-prefix/cypress/integration/navigate.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe(`navigate`, () => {
2929
cy.getTestElement(`subdir-link`)
3030
.click()
3131
.location(`pathname`)
32-
.should(`eq`, `${pathPrefix}/subdirectory/page-1`)
32+
.should(`eq`, withTrailingSlash(`${pathPrefix}/subdirectory/page-1`))
3333
})
3434

3535
it(`can navigate to a sibling page`, () => {
@@ -38,7 +38,7 @@ describe(`navigate`, () => {
3838
.getTestElement(`page-2-link`)
3939
.click()
4040
.location(`pathname`)
41-
.should(`eq`, `${pathPrefix}/subdirectory/page-2`)
41+
.should(`eq`, withTrailingSlash(`${pathPrefix}/subdirectory/page-2`))
4242
})
4343

4444
it(`can navigate to a parent page`, () => {
@@ -47,7 +47,7 @@ describe(`navigate`, () => {
4747
.getTestElement(`page-parent-link`)
4848
.click()
4949
.location(`pathname`)
50-
.should(`eq`, `${pathPrefix}/subdirectory`)
50+
.should(`eq`, withTrailingSlash(`${pathPrefix}/subdirectory`))
5151
})
5252

5353
it(`can navigate to a sibling page programatically`, () => {
@@ -56,7 +56,7 @@ describe(`navigate`, () => {
5656
.getTestElement(`page-2-button-link`)
5757
.click()
5858
.location(`pathname`)
59-
.should(`eq`, `${pathPrefix}/subdirectory/page-2`)
59+
.should(`eq`, withTrailingSlash(`${pathPrefix}/subdirectory/page-2`))
6060
})
6161

6262
it(`can navigate to SSR page`, () => {

‎e2e-tests/production-runtime/cypress/integration/1-production.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ describe(`Production build tests`, () => {
5050
.getTestElement(`subdir-link`)
5151
.click()
5252
.location(`pathname`)
53-
.should(`eq`, `/subdirectory/page-1`)
53+
.should(`eq`, `/subdirectory/page-1/`)
5454
})
5555

5656
it(`can navigate to a sibling page`, () => {
@@ -59,7 +59,7 @@ describe(`Production build tests`, () => {
5959
.getTestElement(`page-2-link`)
6060
.click()
6161
.location(`pathname`)
62-
.should(`eq`, `/subdirectory/page-2`)
62+
.should(`eq`, `/subdirectory/page-2/`)
6363
})
6464

6565
it(`can navigate to a parent page`, () => {
@@ -68,7 +68,7 @@ describe(`Production build tests`, () => {
6868
.getTestElement(`page-parent-link`)
6969
.click()
7070
.location(`pathname`)
71-
.should(`eq`, `/subdirectory`)
71+
.should(`eq`, `/subdirectory/`)
7272
})
7373

7474
it(`can navigate to a sibling page programatically`, () => {
@@ -77,7 +77,7 @@ describe(`Production build tests`, () => {
7777
.getTestElement(`page-2-button-link`)
7878
.click()
7979
.location(`pathname`)
80-
.should(`eq`, `/subdirectory/page-2`)
80+
.should(`eq`, `/subdirectory/page-2/`)
8181
})
8282
})
8383

@@ -224,15 +224,15 @@ describe(`Production build tests`, () => {
224224
})
225225

226226
describe(`Keeps search query`, () => {
227-
describe(`No trailing slash canonical path (/slashes/no-trailing)`, () => {
227+
describe(`Converts no trailing slash canonical path to trailing (/slashes/no-trailing)`, () => {
228228
it(`/slashes/no-trailing?param=value`, () => {
229229
cy.visit(`/slashes/no-trailing?param=value`).waitForRouteChange()
230230

231231
cy.getTestElement(`search-marker`)
232232
.invoke(`text`)
233233
.should(`equal`, `?param=value`)
234234

235-
cy.location(`pathname`).should(`equal`, `/slashes/no-trailing`)
235+
cy.location(`pathname`).should(`equal`, `/slashes/no-trailing/`)
236236
cy.location(`search`).should(`equal`, `?param=value`)
237237
})
238238

@@ -243,7 +243,7 @@ describe(`Production build tests`, () => {
243243
.invoke(`text`)
244244
.should(`equal`, `?param=value`)
245245

246-
cy.location(`pathname`).should(`equal`, `/slashes/no-trailing`)
246+
cy.location(`pathname`).should(`equal`, `/slashes/no-trailing/`)
247247
cy.location(`search`).should(`equal`, `?param=value`)
248248
})
249249
})

0 commit comments

Comments
 (0)