Gatsby: Gatsby not creating page with filename "template-create"

Created on 29 Sep 2020  路  2Comments  路  Source: gatsbyjs/gatsby

Description

Gatsby is not picking up a file with the name template-create in any folder/sub-folder within the src/pages directory. Works perfectly fine with other names.

Steps to reproduce

Create a template-create.js or template-create.tsx file anywhere in the src/pages directory and try navigating in the browser.

Have provided a minimal reproduction case here for anyone wanting to try: https://github.com/shripadk/test-repo

Expected result

Should render a page with "Hello World".

Actual result

Get a 404 instead.

This is with template-create.tsx file in src/pages ( https://localhost:8000/template-create )

template-create.tsx in src/pages

This is with template-create.js file in src/pages/admin ( https://localhost:8000/admin/template-create )

template-create.js in src/pages/admin

Environment

 ~/@/test-repo:master > gatsby info --clipboard

  System:
    OS: macOS Mojave 10.14.6
    CPU: (4) x64 Intel(R) Core(TM) i5-7500 CPU @ 3.40GHz
    Shell: 2.6.0 - /usr/local/bin/fish
  Binaries:
    Node: 10.18.1 - /usr/local/bin/node
    Yarn: 1.22.5 - ~/.yarn/bin/yarn
    npm: 6.13.4 - /usr/local/bin/npm
  Languages:
    Python: 2.7.14 - /Users/shripadkrishna/.nix-profile/bin/python
  Browsers:
    Chrome: 85.0.4183.121
    Firefox: 74.0
    Safari: 14.0
  npmPackages:
    gatsby: ^2.24.66 => 2.24.66
    gatsby-image: ^2.4.20 => 2.4.20
    gatsby-plugin-manifest: ^2.4.32 => 2.4.32
    gatsby-plugin-offline: ^3.2.29 => 3.2.29
    gatsby-plugin-react-helmet: ^3.3.12 => 3.3.12
    gatsby-plugin-sharp: ^2.6.37 => 2.6.37
    gatsby-source-filesystem: ^2.3.31 => 2.3.31
    gatsby-transformer-sharp: ^2.5.16 => 2.5.16
question or discussion

Most helpful comment

Thank you for opening this!

This is expected behavior as Gatsby ignores files starting with template-. The previous behavior was added back in 2016 -- probably with the intention that people can store their templates in src/pages without creating pages for them.

Anyways, removing that behavior would be a breaking change so for now you'll need to rename your files if your intention for them is to be created :)

We're marking this issue as answered and closing it for now but please feel free to comment here if you would like to continue this discussion. We also recommend heading over to our communities if you have questions that are not bug reports or feature requests. We hope we managed to help and thank you for using Gatsby!

All 2 comments

Thank you for opening this!

This is expected behavior as Gatsby ignores files starting with template-. The previous behavior was added back in 2016 -- probably with the intention that people can store their templates in src/pages without creating pages for them.

Anyways, removing that behavior would be a breaking change so for now you'll need to rename your files if your intention for them is to be created :)

We're marking this issue as answered and closing it for now but please feel free to comment here if you would like to continue this discussion. We also recommend heading over to our communities if you have questions that are not bug reports or feature requests. We hope we managed to help and thank you for using Gatsby!

@LekoArts Thank you so much for the clarification. I did not know this as it wasn't documented anywhere. Makes complete sense.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

3CordGuy picture 3CordGuy  路  3Comments

ferMartz picture ferMartz  路  3Comments

andykais picture andykais  路  3Comments

magicly picture magicly  路  3Comments

KyleAMathews picture KyleAMathews  路  3Comments