简体   繁体   English

使用github页面的create-react-app的自定义域

[英]Custom domain using create-react-app for github pages

I'm not sure what I'm doing wrong. 我不确定自己在做什么错。 i've followed all the steps to set up a custom domain name, but maybe I'm missing something. 我已经按照所有步骤设置了自定义域名,但是也许我遗漏了一些东西。

I followed the steps in this article so my settings look like this: 我按照本文中的步骤进行操作,因此我的设置如下所示:

A Record @ 192.30.252.153 Automatic A Record @ 192.30.252.153 Automatic
A Record @ 192.30.252.154 Automatic A Record @ 192.30.252.154 Automatic
CNAME Record www myusername.github.io. CNAME Record www myusername.github.io. Automatic

I added a CNAME file which only has my domain name in it. 我添加了一个仅包含域名的CNAME文件。

I added the CNAME file to the public folder of my react app as the instructions here state. 我按照此处的说明将CNAME文件添加到了我的react应用的公共文件夹中。

I went to my github settings and set the domain name. 我进入github设置并设置了域名。 It currently has a checkmark saying that my site has been published. 当前带有复选标记,表示我的网站已发布。

Going to my site here gives a 404 error. 转到我的网站这里会出现404错误。 What else am I supposed to do? 我还应该做什么?

It is definitely not giving a 404. It seems some of the links to your loaded js/css files are malformed, but the index.html is loading just fine. 它绝对不会提供404。似乎到已加载的js / css文件的某些链接格式错误,但index.html加载就很好。

You should keep in mind that your ISP and your computer both try to cache information about where a given domain name should route to. 您应该记住,您的ISP和计算机都试图缓存有关给定域名应路由到的位置的信息。 This can sometimes mean that the path to the destination IP is cached and will show you the out of date resource immediately after a new CNAME is added. 有时这可能意味着将缓存目标IP的路径,并会在添加新的CNAME之后立即向您显示过期资源。

Most ISPs guarantee a refresh of the related cache within 48 hours. 大多数ISP保证在48小时内刷新相关的缓存。 If you need to check faster than that, I would try to find a different internet connection and device to use to access the page after you have everything set up. 如果您需要检查得更快,那么在完成所有设置后,我会尝试查找其他互联网连接和设备来访问该页面。 Smart Phones are invaluable for this, just make sure the wifi is turned off. 智能手机对此无价之宝,只需确保关闭wifi。

I had a similar issue when trying to set a custom domain with create-react-app on a github project page. 尝试在github项目页面上使用create-react-app设置自定义域时遇到类似的问题。

An easy solution worked for me is: 一个对我有用的简单解决方案是:

  1. Add a "CNAME" file in the "public" folder with only the domain in this file(start with "www" without "https://"); 在“公用”文件夹中添加仅包含域的“ CNAME”文件(以“ www”开头,不带“ https://”);

  2. Change the homepage in the "package.json" file from " https://xxx.github.io/xxx " to your domain that you put in the "CNAME" file with "https://"; 将“ package.json”文件中的主页从“ https://xxx.github.io/xxx ”更改为您使用“ https://”放置在“ CNAME”文件中的域;

  3. In Git Bash, follow the basic steps 'git add .', 'git commit -m "change"', 'git push origin master' to update the changes; 在Git Bash中,遵循基本步骤'git add。','git commit -m“ change”','git push origin master'更新更新;

  4. In Git Bash still, run "npm run deploy", then type the domain in your browser (clear previous history), it should show up the lovely "welcome to React" page. 仍然在Git Bash中,运行“ npm run deploy”,然后在浏览器中键入域(清除以前的历史记录),它将显示可爱的“欢迎使用React”页面。

Regards, 问候,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用create-react-app + github页面的自定义域名 - Custom domain name with create-react-app + github pages 在Github Pages上更改为自定义域会导致带有react-router的create-react-app停止工作 - Changing to custom domain on Github Pages causes create-react-app with react-router to stop working 如何以root用户身份使用create-react-app更新自定义GitHub Pages - how to update a custom GitHub Pages with create-react-app as root 使用 create-react-app 将 React 应用程序部署到 github 页面不起作用 - Deploy React app using create-react-app to github pages isn't working 图像无法为具有自定义域名的 Github 页面(create-react-app)呈现 - Images not rendering for Github Page (create-react-app) with custom domain name Github页面上的Create-React-App返回一个空白页面 - Create-React-App on Github-pages returns a blank page 无法将 create-react-app 部署到 github-pages - cannot deploy create-react-app to github-pages 无法在 Github 页面上部署新的 create-react-app - Cannot deploy fresh create-react-app on Github Pages 将React Webpack应用程序(不是使用create-react-app创建)部署到Github页面 - Deploying a React Webpack app (not created with create-react-app) to Github pages 无法使用Create-React-App在github页面中发布我的React App-控制台出现错误 - Cannot publish my react App in github Pages with Create-React-App - got an Error in console
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM