Skip to content

createPage route params not getting passed to component #3015

@rgdelato

Description

@rgdelato

Hello there!

When I pass a route param to a page created with the createPage action creator in gatsby-node.js (such as /user/:id), the param (in this case, id) isn't included in the props of the component that gets rendered.

To double-check, I made a fresh gatsby new project using [email protected].

Here's the contents of gatsby-node.js:

const path = require(`path`);

exports.createPages = ({ boundActionCreators }) => {
  const { createPage } = boundActionCreators;

  return new Promise((resolve, reject) => {
    createPage({
      path: "/user/:id",
      component: path.resolve(`./src/test.js`)
    });
    resolve();
  });
};

With that, when I navigate to something like /user/22972379663372344, my test.js component is rendered and receives the following props (note that props.match.params should have an id, but it doesn't):

{
  "page":true,
  "match":{
    "path":"/",
    "url":"/",
    "params":{},
    "isExact":false
  },
  "location":{
    "pathname":"/user/22972379663372344",
    "search":"",
    "hash":""
  },
  "history":{
    "length":4,
    "action":"POP",
    "location":{
      "pathname":"/user/22972379663372344",
      "search":"",
      "hash":""
    }
  },
  "pageResources":{
    "json":{
      "pathContext":{}
    },
    "page":{
      "componentChunkName":"component---src-templates-test-js",
      "layout":"index",
      "layoutComponentChunkName":"component---src-layouts-index-js",
      "jsonName":"user-id.json",
      "path":"/user/:id"
    }
  },
  "pathContext":{}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions