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

Add note that router doesn't work with gh-pages #279

Merged
merged 2 commits into from
Jul 29, 2016
Merged

Add note that router doesn't work with gh-pages #279

merged 2 commits into from
Jul 29, 2016

Conversation

rafgraph
Copy link
Contributor

No description provided.

@facebook-github-bot
Copy link

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at cla@fb.com. Thanks!

@ghost
Copy link

ghost commented Jul 29, 2016

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@ghost ghost added the CLA Signed label Jul 29, 2016
@@ -346,6 +346,8 @@ git checkout -

You may copy and paste them, or put them into a custom shell script. You may also customize them for another hosting provider.

Note that if you add a router your app won't work with GitHub Pages becasue it doesn't natively support single page apps with frontend routing (unless it's the ugly hashtag kind). There is a simple workaround for this by adding a `404.html` file with a redirect script, see [Single Page Apps for GitHub Pages](https://github.com/rafrex/spa-github-pages).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let’s make it clear that it’s not an inherent problem with routers. It’s only relevant for the routers using HTML5 pushState history API under the hood. (I know you know it, but our readers probably won’t.)

Copy link
Contributor

@gaearon gaearon Jul 29, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let’s also avoid words like “simple” and “ugly”. They are very subjective. I would rather have a list of workarounds, like this:

  • You could switch from using HTML5 history API to routing with hashes. The URL will be longer and more verbose (for example, http://user.github.io/todomvc#todos/42). If you use React Router, you can switch to hashHistory for this effect. Read more about different history implementations in React Router.
  • Alternatively, you can use a trick to teach GitHub Pages to handle 404 by redirecting to your index.html page with a special parameter. You would need to add an 404.html file with the redirection code to the build folder before deploying your project, and you’ll need to add code handling that parameter to index.html. You can find a detailed explanation of this technique in this guide.

Copy link
Contributor Author

@rafgraph rafgraph Jul 29, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea that makes sense. I wasn't sure how much detail you wanted in the note since create-react-app doesn't include a router by default. I agree "simple" and "ugly" are more appropriate for a subjective comment than an objective doc.

@rafgraph
Copy link
Contributor Author

rafgraph commented Jul 29, 2016

@gaearon I updated the note about using a router with GitHub Pages, let me know what you think. I liked what you wrote, so I used a bunch of it in the update.

Also, sorry about the patch-1 branch name, that's what was created when I used the "contribute some" link in the readme, and I couldn't figure out how to change it.

@ghost ghost added the CLA Signed label Jul 29, 2016
@gaearon gaearon merged commit 5a0669a into facebook:master Jul 29, 2016
@gaearon
Copy link
Contributor

gaearon commented Jul 29, 2016

Looking good, thank you so much!

@rafgraph rafgraph deleted the patch-1 branch July 29, 2016 19:50
@lock lock bot locked and limited conversation to collaborators Jan 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants