diff --git a/packages/gatsby/src/redux/__tests__/pages.js b/packages/gatsby/src/redux/__tests__/pages.js index f1ff108c469fb..404524586994c 100644 --- a/packages/gatsby/src/redux/__tests__/pages.js +++ b/packages/gatsby/src/redux/__tests__/pages.js @@ -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( { diff --git a/packages/gatsby/src/redux/actions.js b/packages/gatsby/src/redux/actions.js index 1a174ea902d41..756e84a6aef22 100644 --- a/packages/gatsby/src/redux/actions.js +++ b/packages/gatsby/src/redux/actions.js @@ -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`)) @@ -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,