Create Static Pages Programmatically

Share this video with your friends

Send Tweet

To create a page programmatically you need to a few things.

1. Create a template file

under src create a folder called templates and inside of that create a file called pokemon.js.

2. Use the Gatsby createPage node API

in the root of the project create a gatsby-node.js file and add the following code

const path = require(`path`)

exports.createPages = ({ graphql, actions }) => {
  const { createPage } = actions
  const templatePath = path.resolve(
    './src/templates/pokemon.js'
  )

  // use the createPage function to create a page.
  // the createPage function accepts an object as a config
  // {
  //   path: // the path to the page, we want it to be `/user`
  //   component: // the path to the component file
  // }
}