Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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