javascript - AngularJS - 删除 Hashbang 后页面重新加载时出现 404 错误

标签 javascript angularjs hashbang

<分区>

使用

从我的 route 删除 hashbang 之后

$locationProvider.html5Mode(true);

现在当访问一个页面时,例如“domain.com/download”,它将起作用。但是如果我重新加载这个确切的页面,它会给我一个 404 错误。像“domain.com/download”这样的链接只能通过输入“domain.com/#!/download”打开。加载后,它会再次将我重定向到正常的“domain.com/download”页面。

我使用 v1.3.2 进行路由,使用 v1.6.3 进行其他操作(不要问我为什么不制作这个网站,哈哈)。

最佳答案

这就是AngularJS Documentation说:

Using this mode requires URL rewriting on server side, basically you have to rewrite all your links to entry point of your application (e.g. index.html). Requiring a tag is also important for this case, as it allows AngularJS to differentiate between the part of the url that is the application base and the path that should be handled by the application.

您必须将您的 .htaccess 更改为:

RewriteEngine On 
Options FollowSymLinks

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /#/$1 [L]

关于javascript - AngularJS - 删除 Hashbang 后页面重新加载时出现 404 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51861168/

相关文章:

Javascript 命中一个 url 并导致出现一个打开/保存文件对话框(完全没有新窗口)

javascript - POST 服务器返回状态代码 : 415 Unsupported Media Type (Preflight request)

javascript - 带有 Cookie 的 Ng 模型

javascript - 如何从 CSHTML.CS 页面操作 DOM?

javascript - 如何运行我用 JavaScript 编写的代码?

javascript - 如何通过从angular的ng-init传递的Id获取html元素

javascript - Angular、limitTo 和 track by $index

ajax - 如何使用 hashbang url 处理 facebook 分享/点赞?

facebook - Facebook 和新 Twitter URL 中的 shebang/hashbang (#!) 是做什么用的?

ajax - Hashbang URL 使网站难以被 Google 抓取?