Skip to content

Commit

Permalink
page path defaults to '/' (#3325)
Browse files Browse the repository at this point in the history
* page path defaults to '/'

* Add test
  • Loading branch information
luczaki114 authored and KyleAMathews committed Jan 10, 2018
1 parent 2ba0d62 commit f33c415
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
12 changes: 12 additions & 0 deletions packages/gatsby/src/redux/__tests__/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ describe(`Add pages`, () => {
expect(state).toMatchSnapshot()
})

it(`adds an initial forward slash if the user doesn't`, () => {
const action = actions.createPage(
{
path: `hi/`,
component: `/whatever/index.js`,
},
{ id: `test`, name: `test` }
)
const state = reducer(undefined, action)
expect(state[0].path).toEqual(`/hi/`)
})

it(`allows you to add pages with context`, () => {
const action = actions.createPage(
{
Expand Down
10 changes: 5 additions & 5 deletions packages/gatsby/src/redux/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ actions.createPage = (page: PageInput, plugin?: Plugin, traceId?: string) => {
updatedAt: Date.now(),
}

// If the path doesn't have an initial forward slash, add it.
if (internalPage.path[0] !== `/`) {
internalPage.path = `/${internalPage.path}`
}

const result = Joi.validate(internalPage, joiSchemas.pageSchema)
if (result.error) {
console.log(chalk.blue.bgYellow(`The upserted page didn't pass validation`))
Expand All @@ -141,11 +146,6 @@ actions.createPage = (page: PageInput, plugin?: Plugin, traceId?: string) => {
return null
}

// If the path doesn't have an initial forward slash, add it.
if (internalPage.path[0] !== `/`) {
internalPage.path = `/${internalPage.path}`
}

return {
type: `CREATE_PAGE`,
plugin,
Expand Down

0 comments on commit f33c415

Please sign in to comment.