【问题标题】:Why is a file resumeData.json not being loaded properly on github pages after deploy?为什么部署后无法在 github 页面上正确加载文件 resumeData.json?
【发布时间】:2020-06-21 16:23:32
【问题描述】:

所以我关注this tutorialthis personal website template 部署到github 页面。我的个人页面在这里托管:

https://samuelstentz.github.io/react-resume-sam/

master 分支显示了我运行 npm run deploy 的源代码。 (https://github.com/SamuelStentz/react-resume-sam)

但由于某种原因,public/resumeData.json 中的所有信息似乎都没有加载。如果我使用 npm start 在本地运行它,所有这些信息都会显示出来。不知道为什么。我摆弄了这个 url 的路径,它在 App.js 中用 jquery 加载 resumeData.json 并且它没有改变任何东西。我运行 npm run deploy 添加到 github 页面。

getResumeData(){
$.ajax({
  url:'/resumeData.json',
  dataType:'json',
  cache: false,
  success: function(data){
    this.setState({resumeData: data});
  }.bind(this),
  error: function(xhr, status, err){
    console.log(err);
    alert(err);
  }
});

}

有人有任何故障排除提示吗?谢谢。

【问题讨论】:

    标签: jquery reactjs npm github-pages npm-start


    【解决方案1】:

    根据此处的建议,我可以通过将 ajax url 更改为 /{reponame}/resumeData.json 来解决此问题:https://github.com/gitname/react-gh-pages/issues/9

    【讨论】:

      【解决方案2】:

      我可以通过在 gh-pages 中的 static.js 前面手动添加“./”来“解决”这个问题,但我确信有更好的解决方案

      【讨论】:

        猜你喜欢
        • 2023-01-27
        • 2017-02-11
        • 2022-07-22
        • 2019-02-11
        • 2023-01-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-10-10
        相关资源
        最近更新 更多