简体   繁体   English

为什么我的 GitHub 页面只显示我的 React 应用程序的主页而不显示其他页面?

[英]Why does my GitHub page only show the homepage for my react app and not the other pages?

So Im trying to deploy my weather app to GitHub Pages and I have installed gh pages as well as added the web link to homepages in my package.json file.所以我试图将我的天气应用程序部署到 GitHub 页面,我已经安装了 gh 页面,并在我的 package.json 文件中添加了指向主页的 web 链接。 But when I go on the live site, it only shows the homepage and not the other "subpages" I have.但是当我在实时站点上输入 go 时,它只显示主页而不是我拥有的其他“子页面”。 If I click on the cities on top to get to that page, it shows a 404 error.如果我点击顶部的城市进入该页面,它会显示 404 错误。 What should I do??我应该怎么办??

This is the link I have in package.json: "homepage": "https://mw3981.github.io/Weather_App/"这是我在 package.json 中的链接:“主页”:“https://mw3981.github.io/Weather_App/”

在此处输入图像描述

My initial thought is that you have a disconnect between what the router is expecting and how Github pages serves pages from within a repo.我最初的想法是,路由器的期望与 Github 页面如何从存储库中提供页面之间存在脱节。

Github always wants to have "/Weather_App/" at the start of the path. Github 总是希望在路径的开头有“/Weather_App/”。 (so the homepage is "https://mw3981.github.io/Weather_App/") (所以主页是“https://mw3981.github.io/Weather_App/”)

The router in react isn't expecting this, so when it tries to serve a subpage it's trying to go to "https://mw3981.github.io/subpage" instead of what github is expecting: "https://mw3981.github.io/Weather_App/subpage" React 中的路由器并不期望这一点,因此当它尝试为子页面提供服务时,它会尝试将 go 转换为“https://mw3981.github.io/subpage”,而不是 github 所期望的:“https://mw3981. github.io/Weather_App/subpage”

Try adding/using basename the prop mentioned here .尝试添加/使用basename此处提到的道具。

Also, there may be some compatibility issues between Github Pages and how the router is doing page changes via pushState .此外,Github 页面与路由器如何通过pushState进行页面更改之间可能存在一些兼容性问题。 That's discussed here .这是在这里讨论的。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM