Skip to content
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

Allow /404 file to act as wildcard route #121

Merged
merged 1 commit into from
Mar 7, 2016
Merged

Allow /404 file to act as wildcard route #121

merged 1 commit into from
Mar 7, 2016

Conversation

scottnonnenberg
Copy link
Contributor

Didn't see a way to put a 'not found' page in place, thought I'd add one.

Scenario: I've created a 404 page for nginx, but when it loads fully I get an empty screen because react-router doesn't know about the random URL the user attempted to load. This change allows me to put a 404.jsx somewhere in the project, and that is automatically registered as the wildcard handler.

@KyleAMathews
Copy link
Contributor

@scottnonnenberg Gatsby is using React Router 2.0 now which means the syntax for adding wildcard routes has changed somewhat. Would you mind creating a new PR against master?

@scottnonnenberg
Copy link
Contributor Author

Updated! Includes my changes from #174.

@scottnonnenberg
Copy link
Contributor Author

Rebased on latest master.

@KyleAMathews
Copy link
Contributor

Thanks!

So one quick thought looking at this — I think this * route is going to cause problems right now. React Router matches routes top-to-bottom which means this 404 route will block every route defined after it.

So I think the algorithm should be:

  1. add routes for all pages except the 404 page.
  2. add a route for the 404 page (if there is one) to the end of the list.

Thoughts?

@scottnonnenberg
Copy link
Contributor Author

Good call. Closer to my original implementation.

That should do it! Nice to be online at about the same time. :0)

@KyleAMathews
Copy link
Contributor

Indeed :)

Thanks! Merging and I'll do a quick new release.

If you have a bit more time, adding a follow-up PR to document this in the README.md would be 💯

KyleAMathews added a commit that referenced this pull request Mar 7, 2016
Allow /404 file to act as wildcard route
@KyleAMathews KyleAMathews merged commit 0b5bed5 into gatsbyjs:master Mar 7, 2016
@KyleAMathews
Copy link
Contributor

Published 0.8.7 with this 💯 Will also add a sample 404 page to the three official starters. This is awesome thanks @scottnonnenberg!

@clouddra
Copy link

thanks @scottnonnenberg for 404 page routing.
It works when I tried running in develop mode but breaks when I ran the built version of the site.
I have also tried testing it on the official starters and it does not work as well.

@KyleAMathews
Copy link
Contributor

Can you give more details? e.g. Steps to reproduce?
On Wed, Mar 9, 2016 at 6:57 PM clouddra notifications@github.com wrote:

thanks @scottnonnenberg https://github.com/scottnonnenberg for 404 page
routing.
It works when I tried running in develop mode but breaks when I ran the
built version of the site.
I have also tried testing it on the official starters and it does not work
as well.


Reply to this email directly or view it on GitHub
#121 (comment).

@scottnonnenberg
Copy link
Contributor Author

One thing to keep in mind is that for the built version of the site, you need to set up your server to show the 404 file anytime it can't find a real file on disk. In nginx, that looks like this:

error_page 404 /404/index.html;

Note that this will NOT work if you're just using a simple pass-through file server like python -m SimpleHTTPServer 8000

@clouddra
Copy link

@KyleAMathews
if you have you pushed 404 pages into your starters' gh-pages you can try this http://gatsbyjs.github.io/gatsby-starter-documentation/some_link

@scottnonnenberg
From what you have said I presume that it would not work for gh-pages?

@scottnonnenberg
Copy link
Contributor Author

For github pages, looks like our path might not match (their /404.html vs our /404/index.html), and you'll need to have a custom domain: https://help.github.com/articles/creating-a-custom-404-page-for-your-github-pages-site/

Simple solution for now: copy the file to the location github pages expects, and move your github pages to custom domain.

@KyleAMathews
Copy link
Contributor

@scottnonnenberg great research. @clouddra I switched the 404 url in starters to /404.html e.g. gatsbyjs/gatsby-starter-documentation@7534eed to simplify getting started on something like this.

@clouddra
Copy link

@scottnonnenberg @KyleAMathews Thanks for the help. Will try it out.

@scottnonnenberg scottnonnenberg deleted the not-found branch April 14, 2016 17:45
@SachaG
Copy link
Contributor

SachaG commented Aug 23, 2016

@KyleAMathews should the same frontmatter appear in here, too?

https://github.com/gatsbyjs/gatsby-starter-default/blob/master/pages/404.md

@KyleAMathews
Copy link
Contributor

@SachaG yes it should :-) I'll add that real quick. Thanks for bringing your fine-toothed bug-finder comb!

@jlengstorf
Copy link
Contributor

Hiya @scottnonnenberg! 👋

This is definitely late, but on behalf of the entire Gatsby community, I wanted to say thank you for being here.

Gatsby is built by awesome people like you. Let us say “thanks” in two ways:

  1. We’d like to send you some Gatsby swag. As a token of our appreciation, you can go to the Gatsby Swag Store and log in with your GitHub account to get a coupon code good for one free piece of swag. (We’ve got t-shirts and hats, plus some socks that are really razzing our berries right now.)
  2. If you’re not already part of it, we just invited you to join the Gatsby organization on GitHub. This will add you to our team of maintainers. You’ll receive an email shortly asking you to confirm. By joining the team, you’ll be able to label issues, review pull requests, and merge approved pull requests.

If you have questions, please don’t hesitate to reach out to us: tweet at @gatsbyjs and we’ll come a-runnin’.

Thanks again! 💪💜

1 similar comment
@jlengstorf
Copy link
Contributor

Hiya @scottnonnenberg! 👋

This is definitely late, but on behalf of the entire Gatsby community, I wanted to say thank you for being here.

Gatsby is built by awesome people like you. Let us say “thanks” in two ways:

  1. We’d like to send you some Gatsby swag. As a token of our appreciation, you can go to the Gatsby Swag Store and log in with your GitHub account to get a coupon code good for one free piece of swag. (We’ve got t-shirts and hats, plus some socks that are really razzing our berries right now.)
  2. If you’re not already part of it, we just invited you to join the Gatsby organization on GitHub. This will add you to our team of maintainers. You’ll receive an email shortly asking you to confirm. By joining the team, you’ll be able to label issues, review pull requests, and merge approved pull requests.

If you have questions, please don’t hesitate to reach out to us: tweet at @gatsbyjs and we’ll come a-runnin’.

Thanks again! 💪💜

ChristopherBiscardi pushed a commit to ChristopherBiscardi/gatsby that referenced this pull request Jun 9, 2019
ChristopherBiscardi pushed a commit to ChristopherBiscardi/gatsby that referenced this pull request Jun 27, 2019
johno pushed a commit to johno/gatsby that referenced this pull request Jul 17, 2019
pragmaticpat pushed a commit to pragmaticpat/gatsby that referenced this pull request Apr 28, 2022
feat: add an seo component that can be used between pages/templates
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants