0

I'm facing issues when i try to create custom pages in Gatsby. I have deleted every files in pages folder other than app.js file. Now, i check for page path '/app' in onCreatePage function in gatsby-node.js. If it's found, i change the path from '/app' to '/' and create that page. After that i'll use the app.js file to route to different pages.

When everything's done and i check the routes in the browser, it's giving me an error saying 'Cannot read property page of undefined' for the route '/our-work'. I get the error only when i go to the route '/our-work'.And the default 'NotFound' page is not working. The main page gets displayed on every routes other than '/our-work' route no matter what.

Please go through the images below. Thanks!

app.js:

app.js

gatsby-node.js:

gatsby-node.js

The main route - '/':

The main route - '/'

The problematic route - '/our-work':

The problematic route - '/our-work'

The main page gets displayed on route where the NotFound component is expected to function:

The main page gets displayed on route where the NotFound component is expected to function

Deepak S.M
  • 51
  • 1
  • 9
  • There are a few things here. First for the `NotFound`, I can't see it in your `pages` directory. Why do you expect it to catch 404s? See [the docs](https://www.gatsbyjs.org/docs/add-404-page/). Then for the `onCreatePages` error, it would be great if you could [post code snippets, not images](https://stackoverflow.com/help/how-to-ask) and in your case maybe provide a reproduction repo to make helping you easier. – Robin Métral Feb 07 '20 at 07:40
  • When you add or remove pages you should run `gatsby develop` again. This is because of the way Gatsby builds pages and adds them to the webpack bundle. On the fly, it is likely that there will be errors that disappear when you properly build your project again. Try your changes while using `gatsby develop` everytime you add or remove pages. Do you still get those errors? – EliteRaceElephant Feb 08 '20 at 07:01

0 Answers0