Hi everyone,
I’ve been struggling to understand rules applied by Netlify’s platform, although I read documentation carefully several times.
My use case is like following:
- Gatsby website with the following structure
- Page in
/pages/initiatives.jsx
which is going to serve a client-only route as described in Gatsby’s docs
The code in gatsby-node.js
looks like following:
if (page.path.match(/^\/initiatives/)) {
/* eslint-disable no-param-reassign */
page.matchPath = '/initiatives/*';
return createPage({
...page,
context: {
...page.context,
layout: 'dynamic',
},
});
}
At this point, when I run gatsby develop
and when I open localhost:8000/initiatives/open-2019-000011
or localhost:8000/initiatives/open/2019/000011
I reach the contents of /pages/initiatives.jsx
.
I would like to find a way to have the same behavior on Netlify.
What I’ve tried so far:
# The following redirect is intended for SPAs that handle routing internally.
[[redirects]]
from = "/initiatives/*"
to = "/initiatives/index.html"
status = 200
I do confirm that /initiatives/index.html
exists in the public
folder, built by Gatsby and served by Netlify.
At this point, I do get to reach the contents of /pages/initiatives.jsx
at https://foo-preview.netlify.com/initiatives/
, but I can’t have //foo-preview.netlify.com/initiatives/foo
. As soon as I open //foo-preview.netlify.com/initiatives/foo
, I get to //foo-preview.netlify.com/initiatives/
.
This is strange I think, because documentation says This means that in addition to redirects, you can define rewrite rules by specifying 200 as the status code
. (reference)
Same behavior holds true with
[[redirects]]
from = "/initiatives/*"
to = "/initiative/:splat"
status = 200
[[redirects]]
# initiatives/open/details/2019/000010
from = "/initiatives/:status/:action/:year/:number"
to = " /initiative/:year/:month/:date/:slug"
Having force = true
, a single path element or even
[[redirects]]
from = "/initiatives/*"
to = "/initiatives/index.html/:slug"
status = 200
force = false
I tried to use gatsby-plugin-create-client-paths but It’s not quite getting there in terms of redirects I think, as the automatically generated _redirects
becomes
## Created with gatsby-plugin-netlify
/initiatives/* /initiatives/ 200
Any ideas what I’m doing wrong?
PS No links to documentation because my account is new and limited.