Skip to content

Commit

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

* Add test
  • Loading branch information
luczaki114 authored and jastack committed Jan 24, 2018
1 parent 40df85e commit 396ae6e
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 396ae6e

Please sign in to comment.