0

我已经在 Angular 中实现了漂亮的 url(切换到 html5mode)。

当我刷新页面时,出现 404 错误。

例如:如果我使用http://server/打开我的应用程序,一切正常,但是当我引用页面或尝试打开特定页面 ex http://server/mypage时,我收到 404 错误。

笔记:

  • 编译我的应用程序时,我在 javascript 中组合模板。
  • 编译后,我的脚本(带模板)进入构建文件夹,index.html 中的基本标记设置为“/”;。

  • 我正在使用 Angular-ui-router。

  • 使用 .net 作为后端。
  • 前端应用程序与后端完全分开,两者都部署在 IIS 中。

请提出错误的可能解决方案或原因。

谢谢

4

1 回答 1

0

你应该检查你在后端的设置,当我使用 html5 历史时,我有我的 .htaccess 文件(你将所有请求重定向到你的根 index.php 或 index.html 文件),看看我的 .htaccess:

RewriteEngine On  
  # If an existing asset or directory is requested go to it as it is
  RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
  RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
  RewriteRule ^ - [L]

  # If the requested resource doesn't exist, use index.html
  RewriteRule ^ /index.html

如果这没有帮助,您可以阅读此[文章]

于 2017-07-06T13:06:20.633 回答