angularjs html5mode刷新页面获取404 [英] angularjs html5mode refresh page get 404

查看:1721
本文介绍了angularjs html5mode刷新页面获取404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建使用AngularJS与GAE(谷歌应用程序引擎 - 的Java)的应用程序。

I've created an app using AngularJS with GAE (Google App Engine – Java).

我想转换它与搜索引擎优化兼容。

I want to convert it compatible with SEO.


  • <!META NAME =片段的内容= />

  • <基本href =/>

  • <meta name="fragment" content="!" />
  • <base href="/">

和身体通过&LT动态加载;格UI的视图&gt;&LT; / DIV&GT;

$ locationProvider.html5Mode(真);

该网址工作正常,但是当我刷新页面,我得到404错误。

The url works fine but when I refresh page I get 404 error.

你有什么想法,这是什么原因造成的?

Do you have any idea, what this causes?

推荐答案

我敢肯定你已经解决了这一点,但对于其他人遇到了这个问题:

I'm sure you've already solved this, but for anybody else running into this issue:

基本上AngularJS的 $ locationProvider.html5mode(真)利用HTML5的的 history.pushState(),人为地改变用户的历史记录和地址栏URL无需重新加载页面。如果创建一个关于路线(以角)为 /,但不具备服务器上的任何匹配的路由,你会遇到的问题,即重新加载页面揭示了事实上,它是不存在的服务器上。最简单的办法,就是反映出入口点的应用程序( /index.html ?),供您的应用程序访问的所有路由。

Basically AngularJS's $locationProvider.html5mode(true) makes use of HTML5's history.pushState(), which artificially changes the user's history and address bar URL without reloading the page. If you create a route (in Angular) for /about, but don't have any matching route on the server, you will run into the issue where reloading the page reveals the fact that it's not there on the server. The simplest solution is to mirror your entry point for your app (/index.html?) for all routes accessible by your app.

请参阅:<一href=\"http://stackoverflow.com/a/16570533/1500501\">http://stackoverflow.com/a/16570533/1500501

这篇关于angularjs html5mode刷新页面获取404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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