使用
从我的 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]