4

当我从索引访问我的页面并开始浏览时,一切正常,但是当我在除/例如 in之外的路线上/details/123并刷新页面(我配置了 URL 重写)时,路线未正确设置。
这意味着,当我从索引正常浏​​览时检查位置路径并且我在/details/123位置路径上是/details/123预期的,但是当我刷新页面并且我仍然在/details/123位置路径上时,会/123导致 ngView 显示错误的视图。
我正在使用 html5 模式和 Angular v.1.1.5

更新:我在这里创建了一个简单的示例来说明问题。
我没有任何特殊设置,我认为不是服务器问题。我在 python 中的另一个应用程序中遇到了同样的问题,其中重定向是在应用程序内部完成的。:
_.htaccess

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)       /index.php
</IfModule>
4

1 回答 1

8

This may be related to a nasty issue that showed up during Angular 1.1.5 and is a bug in the core library. A solution that has worked for many is to add the following tag to your index.html head.

If your application is running at the root of your domain.

<head>
  ...
  <base href="/"></base>
  ...
</head>

Or if your application is running in a subdirectory, specify that subdirectory (e.g. 'myapp'):

<head>
  ...
  <base href="/myapp/"></base>
  ...
</head>

Additionally, you may also try a new set of rewrite rules. This configuration has worked for many ui-router users.

<IfModule mod_rewrite.c>
  RewriteEngine on

  # Don't rewrite files or directories
  RewriteCond %{REQUEST_FILENAME} -f [OR]
  RewriteCond %{REQUEST_FILENAME} -d
  RewriteRule ^ - [L]

  # Rewrite everything else to index.html to allow html5 state links
  RewriteRule ^ index.html [L]
</IfModule>
于 2013-08-07T13:42:34.257 回答