Gatsby plugin that automatically creates pages from React components in specified directories
npm install gatsby-plugin-page-creatorGatsby plugin that automatically creates pages from React components in specified directories. Gatsby
includes this plugin automatically in all sites for creating pages from components in src/pages. You can also leverage the File System Route API to programmatically create pages from your data.
You may include another instance of this plugin if you'd like to create additional "pages" directories or want to override the default usage.
With this plugin, _any_ file that lives in the specified pages folder (e.g. the default src/pages) or subfolders will be expected to export a React Component to generate a Page. The following files are automatically excluded:
- template-*
- __tests__/*
- *.test.jsx?
- *.spec.jsx?
- *.d.tsx?
- *.json
- *.yaml
- _*
- .*
To exclude custom patterns, see Ignoring Specific Files
npm install gatsby-plugin-page-creator
Add the plugin to your gatsby-config.js:
``javascript
// gatsby-config.js
module.exports = {
plugins: [
// You can have multiple instances of this plugin
// to create pages from React components in different directories.
//
// The following sets up the pattern of having multiple
// "pages" directories in your project
{
resolve: gatsby-plugin-page-creator,${__dirname}/src/account/pages
options: {
path: ,gatsby-plugin-page-creator
},
},
{
resolve: ,${__dirname}/src/settings/pages
options: {
path: ,gatsby-plugin-page-creator
},
},
// You can also overwrite the default behavior for src/pages
// This changes the page-creator instance used by Gatsby
{
resolve: ,${__dirname}/src/pages
options: {
path: ,foo-bar.js
ignore: [],`
},
},
],
}
The plugin supports options to ignore files and to pass options to the slugify instance that is used in the File System Route API to create slugs.
| Option | Type | Description | Required |
| ------- | ---------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------- |
| path | string | Any file that lives inside this directory will be expected to export a React component to generate a page | true |IPathIgnoreOptions ∣ string ∣ Array
| ignore | | Ignore certain files inside the directory specified with path | false |ISlugifyOptions
| slugify | | Pass options to the slugify instance that is used inside the File System Route API to generate the slug | false |
#### Shorthand
The following example will disable the /blog index page:
`javascriptgatsby-plugin-page-creator
// gatsby-config.js
module.exports = {
plugins: [
{
resolve: ,${__dirname}/src/indexes/pages
options: {
path: ,blog.(js|ts)?(x)
ignore: [],`
// See pattern syntax recognized by micromatch
// https://www.npmjs.com/package/micromatch#matching-features
},
},
],
}
NOTE: The above code snippet will only stop the creation of the /blog page, which is defined as a React component.
This plugin does not affect programmatically generated pages from the createPages API.
#### Ignore Options
The following example will ignore pages using case-insensitive matching:
`javascriptgatsby-plugin-page-creator
// gatsby-config.js
module.exports = {
plugins: [
{
resolve: ,${__dirname}/src/examples/pages
options: {
path: ,file.example.js
ignore: {
// Example: Ignore , dir/s/file.example.tsx*/.example.(js|ts)?(x)
patterns: [],file.example.js
// Example: Match both and file.EXAMPLE.js``
options: { nocase: true },
// See all available micromatch options
// https://www.npmjs.com/package/micromatch#optionsnocase
},
},
},
],
}