0

I was wondering if there's an option to create a Gatsby page with optional URL parameters of sort. Let's say that I've got listing of articles with an URL set to /articles/:articleID - this works really well, but the /articles page is just blank, without errors or anything and I'd like to create a handler page for that, maybe a 404 or a list of all articles, for example.

AFAIK Gatsby uses React-Router, so I changed my URLs to /articles/:articleID?, but it still doesn't work.

I'm creating all these pages with createPages API, like this:

    // ...

    createPage({
      path: page.url,
      matchPath: `${page.url}${pageParams}`, 
      component: path.resolve(`./src/templates/${page.template}.js`),
      context: {
        ...page.props,
      }
    });

where page is a simple object that contains data like url, template and stuff. pageParams is just a string that looks like this: /:articleID?.

Any tips on how to handle the page without any parameters? Because the template isn't loaded, but there is also no error for that page.

  • Possible duplicate of [How to create dynamic route in gatsby](https://stackoverflow.com/questions/55756994/how-to-create-dynamic-route-in-gatsby) – ksav Oct 25 '19 at 10:18
  • I based my code on that topic, to be honest. The dynamic part works properly, I just want to add a handler for a page without any `articleID`. `/articles/test-article` works, `/articles` is just a blank page with no error, no template. –  Oct 25 '19 at 11:24
  • Where do the articles come from? – ksav Oct 25 '19 at 12:17
  • Also, add your `articles` component to the question. – ksav Oct 25 '19 at 12:19

0 Answers0