【问题标题】:Angular 6 - Page not displaying after refreshing the pageAngular 6 - 刷新页面后页面不显示
【发布时间】:2019-02-11 17:55:51
【问题描述】:

我正在使用 Angular 6。我的应用程序在本地运行良好。我已经使用ng build 构建了代码。我正在使用 Ubuntu 服务器。我已将代码上传到服务器,页面也正在加载。

但是当我刷新页面时,我收到以下错误。

您要查找的资源已被删除、更改名称或暂时不可用。

我已经粘贴了我的 index.html 代码。

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>WAF</title>
  <base href="/">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
  <link rel="icon" type="image/x-icon" href="assets/images/favicon.png">
</head>
<body>
  <app-root></app-root>
</body>
</html>

并且也尝试过使用 .htaccess 文件。遇到同样的问题。

RewriteEngine On 
Options FollowSymLinks

RewriteBase /

RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} ^/(.*)$
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,L]

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

请帮我解决这个问题。 谢谢

【问题讨论】:

    标签: angular


    【解决方案1】:

    这是 SPA(单页应用)的常见问题。

    基本上,因为这是一个 SPA,所以只有一个页面,即 index.html

    您必须将您的产品服务器配置为始终提供 index.html,而不管当前的路由/网址如何。 Angular 开发服务器开箱即用。

    我希望在您刷新时得到一个 404,因为它找不到 /yoururl - 默认情况下,它会在 /yoururl/index.html 中寻找一个文件,这显然是完全错误的。

    我从来没有在 ubuntu 服务器上做过这个,所以我无法帮助你进行配置,但至少现在你知道问题是什么以及如何研究它。

    【讨论】:

    • 感谢您的回复。会试试这个
    猜你喜欢
    • 2019-02-20
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-20
    • 1970-01-01
    相关资源
    最近更新 更多