Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

page path defaults to '/' #3325

Merged
merged 3 commits into from
Jan 10, 2018
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