if page's matchPath is altered, loader.js cannot find the page #8285
Description
Description
If page's matchPath property is altered in gatsby-node.js, loader.js is not able to find the page in development mode.
Steps to reproduce
in gatsby-node.js, change matchPath of a page:
exports.onCreatePage = ({ page, actions }) => {
const { createPage } = actions
if (page.path === `/mypage/`) {
page.matchPath = `/mypath/*`
createPage(page)
}
}
Expected result
When you browse to /mypath mypage should display
Actual result
In development mode, it is not able to find the page, and showing 404
Check this note: note by pieh by @pieh
There is no need to findPage here as page is already in scope or do findPage by matchPath if it is set
// loader.js
if (process.env.NODE_ENV !== `production`) {
const page = findPage(path)
const pageResources = {
component: syncRequires.components[page.componentChunkName],
page,
}
...
}
Environment
System:
OS: macOS Sierra 10.12.6
CPU: x64 Intel(R) Core(TM) i5-5287U CPU @ 2.90GHz
Shell: 5.2 - /bin/zsh
Binaries:
Node: 9.7.1 - ~/.nvm/versions/node/v9.7.1/bin/node
Yarn: 1.5.1 - /usr/local/bin/yarn
npm: 6.0.0 - ~/.nvm/versions/node/v9.7.1/bin/npm
Browsers:
Chrome: 67.0.3396.99
Firefox: 57.0.4
Safari: 11.0.1
npmPackages:
gatsby: 2.0.1 => 2.0.1
gatsby-cli: 2.0.1 => 2.0.1