score:5

Accepted answer

in gatsby-node.js:

// implement the gatsby api “oncreatepage”. this is
// called after every page is created.
exports.oncreatepage = async ({ page, boundactioncreators }) => {
  const { createpage } = boundactioncreators;

  return new promise((resolve, reject) => {
    if (page.path.match(/^\/landing-page/)) {
      // it's assumed that `landingpage.js` exists in the `/layouts/` directory
      page.layout = "landingpage";

      // update the page.
      createpage(page);
    }

    resolve();
  });
};

create src/layouts/landingpage.js. this will be the new layout template.

create src/pages/landing-page/index.js. this will be the index page for the newly created layout template.

source: creating and modifying pages | gatsbyjs


Related Query

More Query from same tag