Skip to content

Commit 396ae6e

Browse files
luczaki114jastack
authored andcommitted
page path defaults to '/' (gatsbyjs#3325)
* page path defaults to '/' * Add test
1 parent 40df85e commit 396ae6e

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

packages/gatsby/src/redux/__tests__/pages.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@ describe(`Add pages`, () => {
2121
expect(state).toMatchSnapshot()
2222
})
2323

24+
it(`adds an initial forward slash if the user doesn't`, () => {
25+
const action = actions.createPage(
26+
{
27+
path: `hi/`,
28+
component: `/whatever/index.js`,
29+
},
30+
{ id: `test`, name: `test` }
31+
)
32+
const state = reducer(undefined, action)
33+
expect(state[0].path).toEqual(`/hi/`)
34+
})
35+
2436
it(`allows you to add pages with context`, () => {
2537
const action = actions.createPage(
2638
{

packages/gatsby/src/redux/actions.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ actions.createPage = (page: PageInput, plugin?: Plugin, traceId?: string) => {
133133
updatedAt: Date.now(),
134134
}
135135

136+
// If the path doesn't have an initial forward slash, add it.
137+
if (internalPage.path[0] !== `/`) {
138+
internalPage.path = `/${internalPage.path}`
139+
}
140+
136141
const result = Joi.validate(internalPage, joiSchemas.pageSchema)
137142
if (result.error) {
138143
console.log(chalk.blue.bgYellow(`The upserted page didn't pass validation`))
@@ -141,11 +146,6 @@ actions.createPage = (page: PageInput, plugin?: Plugin, traceId?: string) => {
141146
return null
142147
}
143148

144-
// If the path doesn't have an initial forward slash, add it.
145-
if (internalPage.path[0] !== `/`) {
146-
internalPage.path = `/${internalPage.path}`
147-
}
148-
149149
return {
150150
type: `CREATE_PAGE`,
151151
plugin,

0 commit comments

Comments
 (0)