AngularJS 1.0.7在html5Mode获得404错误,当刷新页面 [英] AngularJS 1.0.7 in html5Mode get 404 error when refresh page

查看:144
本文介绍了AngularJS 1.0.7在html5Mode获得404错误,当刷新页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有关于这个话题一些职位。我看过其中大部分,但我觉得我可不是不够熟练,了解我应该怎么办。

I know there are some posts about this topic. I have read most of them, but I think I´m not skilled enough to understand what should I do.

我有一个AngularJS 1.0.7 Web应用程序。我刚才已经配置了它html5Mode至prettify我的网址。我的网址现在看起来不错,但我得到了一个新的问题,我改变之前hadn't。当我第一次加载我的索引页,我可以刷新它没有问题。但是,如果我浏览到的例子在其他页/约,然后我刷新页面,我得到一个404错误。

I have an AngularJS 1.0.7 web application. I have just configured it to html5Mode to prettify my URLs. My URLs looks nice now, but I got a new problem I hadn´t before the change. When I first load my index page, I can refresh it without problem. However, if I navigate to some other page in example /about and then I refresh the page I get a 404 Error.

例如在这个职位:<一href=\"http://stackoverflow.com/questions/16569841/angularjs-html5-mode-reloading-the-page-gives-wrong-get-request/16570533#16570533\">AngularJS HTML5模式重新加载页面给出我看过,我应该重写我在服务器端的URL到我的入口点错了GET请求,我想index.html的,但我不具备这意味着什么,以及如何任何想法做到这一点。

For example in this post: AngularJS HTML5 mode reloading the page gives wrong GET request I have read that I should rewrite my urls in server side to my entry point, I guess index.html, but I don´t have any idea about what this means and how to do it.

会有人这么好心提供了更详细一点,实用的例子吗?

Would anybody be so kind to provide a bit more detailed and practical example?

什么是他们的意思是,当他们谈论的服务器?我有一个将请求发送到一个彪马服务器上运行的Rails的API的Nginx的服务器上运行的应用角度。

What does they mean when they talk about the server? I have an Angular application running on an Nginx server that sends requests to a Rails API that runs on a Puma server.

推荐答案

这样的想法是迫使Nginx的指向所有HTPP请求index.html,然后让角做路由在应用程序中。

So the idea is to force Nginx to point all htpp requests to index.html and let the Angular do the routing in your application.

您didn`t张贴任何配置,这里是最基本的:

You didn`t post any configuration so here is the most basic:

server {
 listen 80;
 server_name foobar.com www.foobar.com;
 index index.html;
 root /var/www/mysite;

location / {
  try_files $uri$args $uri$args/ index.html;
 }
}

这篇关于AngularJS 1.0.7在html5Mode获得404错误,当刷新页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆