-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide alternative matchPath routing strategies for different usages. #19228
Comments
There was a brief discord conversation on this topic. . Different createPage function for 404sOne suggestion was to offer an alternative action to create404({path: "/thing/*", component: "my404.tsx", context: { whatever: "beans" }}) Allow
|
Hiya! This issue has gone quiet. Spooky quiet. 👻 We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here. If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open! As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing! Thanks for being a part of the Gatsby community! 💪💜 |
You're right that we need to address the large match-path.json for sites with many pages. The current situation is an organc side effect of moving to individual page jsons. I like the idea of a manually driven api for 404-kinds of fallbacks. Especially if that means we can cut down mega jsons to a single regex ;) I don't have a thorough understanding of the entire system (in this context) yet, but from what I understand we should be able to have a set of manually crafted regexes that could go before the current match-path system, which would prevent a forest of The docs can be solved by examples and tutorials. This is not an issue for the average user and I think that if you really want to achieve this, and spend a little time on going through the docs and examples, that you can get that to work. |
It's not as simple as you think it is. We first had a 404 fetch in place but we got a lot of pushback because of analytics projects not handling 404's correctly. More info #16097 Not saying that we shouldn't fix this but I feel the only way we can is do it on the server with plugins like gatsby-plugin-netlify, ... |
Can we at least have something to work with on a server side? Some header that could tell us whenever that 404 is real or not? Something like X-GATSBY-ROUTED? Without that my prometheus / grafana dashboard would blow up with these 404s. Edit: Actually i ran gatsby build and put it behind nginx and there is no more 404 My simplest config is:
This also created an inverted problem - a real 404 are also not logged by the nginx server |
It might be helpful if Gatsby could provide a standardized/documented manifest of what routing it expects in the build artifacts. My plan, before we switched to a full SSR solution, was to determine what client-side routes existed (to send 404s) using Lambda@Edge, where we were already handling the other routing using a hacked together rewrite function. |
Hiya! This issue has gone quiet. Spooky quiet. 👻 We get a lot of issues, so we currently close issues after 60 days of inactivity. It’s been at least 20 days since the last update here. Thanks for being a part of the Gatsby community! 💪💜 |
Hey again! It’s been 60 days since anything happened on this issue, so our friendly neighborhood robot (that’s me!) is going to close it. Thanks again for being part of the Gatsby community! 💪💜 |
Summary
There are (at least) two broad categories of use cases for client side routing:
Presently static pages within a matchPath wildcard (ie.
*
) route are added as individual items tomatch-paths
, which is great for app developers because it prevents a 404 request forpage-data.json
for every url matched by the wildcard. Correctly handling this is essential for Gatsby to be a viable alternative to things likecreate-react-app
.The fallback wildcard route suffers with this strategy, because the mostly static content does not use the new
page-data
architecture. Instead a very largematch-paths
file is created. For this use case, querying for a static page first and finding a 404 forpage-data.json
is an exceptional event that feels semantically correct.One strategy to help fallback wildcard users would be to provide whatever optimizations are possible, such as loading static paths in
match-paths
to a more a moreO(log n)
flavored data structure on the client side.A much better strategy would be to recognize that the use cases are fundamentally different. Providing some annotation to indicate that a wildcard route is a backup would allow the optimal strategy to be used in all cases. It might even be possible to heuristically pick a default when a wildcard route contains a significant number of static pages.
Implementing this would be relatively simple by adding another catalog of fallback wildcard routes, such as
match-paths-after
containing all fallback annotated paths. Paths would then be searched:match-paths
->query page-data folder
->match-paths-after
. Logic for handling 404s could be updated/replaced withmatch-paths-after
by always placing a route (/* -> 404.js
) at the end ofmatch-paths-after
.Basic example
Pages with
matchPath
would be annotated ingatsby-node
.Motivation
Picking just one strategy to handle wildcards will result in an expensive compromise between major groups of users. A nuanced implementation would finally eliminate all friction caused by the switch to the
page-data
folder.The text was updated successfully, but these errors were encountered: