在GitHub产品404错误部署Angular网站 [英] Deploy Angular website on GitHub products 404 error
问题描述
我在GitHub
然而,当我导航到任何产品页面从主页开始,产品页面将正确打开。
这个应用程序的reprository链接是 - here 。
我是初学者角色 - 请帮助我为什么要这么做?
这是因为您使用HTML pushState作为位置策略,因此当您从浏览器刷新时,浏览器会将路由页面的请求发送到Github。由于Github没有意识到这个内部路由由于它显示404错误。
有几个解决方案:
1.如果你想坚持Github,那么你需要移动到基于哈希的位置策略。它将简单地解决你的问题。
2.如果你没有任何依赖Github的话,那么你可以移动到其他支持创建htaccess文件或其他回退机制的服务器(firebase或apache)。 (查看此链接了解更多信息)。不幸的是,这个htaccess文件不被Github支持。由于这些故障,我个人更喜欢firebase。
通过这些回退机制,我的意思是服务器重定向到index.html,即任何404路由的情况下您的主HTML文件。
I have deployed a small static angular website on GitHub Link but it has one problem. When i refresh any products page like this then I get 404 error.
However when i navigate to any products pages from the home page then the product pages opens correctly.
This app's reprository link is - here.
I am beginner in angular - please help me why it is doing so ?
This is because you are using HTML pushState as location strategy due to which when you refresh from browser, the browser sends request of your routed page to Github. As Github is unaware of this internal routing by angular due to it shows 404 error.
There are couple of solutions:
1. If you want to stick to Github then you need to move to HashBased location strategy. It will simply solve your problem.
2. If you don't have any dependency on Github then you can move to other servers (firebase or apache) which support creating a htaccess file or any other fallback mechanism. (See this link for more info). This htaccess file is unfortunately not supported by Github yet. I personally prefer firebase due to these glitches.
By these fallback mechanisms I mean the server redirect to index.html i.e. your main HTML file in case of any 404 routes.
这篇关于在GitHub产品404错误部署Angular网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!