我使用bitnami MEAN堆栈制作了一个在AWS EC2中托管的angular(2+)应用程序。一切正常,除了提供404的角度重装。我知道angular是SPA(单页应用程序),因此我们每次都需要发送index.html文件(这就是为什么会出现此错误)。因此,我进行了一些研究,找到了用于nodejs的代码,并在所有路径后编写了此代码:
app.use('*', (req, res, next) => {
res.sendFile(filePath);
})
但是,我在浏览器中什么也没显示,在浏览器控制台中是:
Failed to load module script: The server responded with a non-JavaScript MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.
注意:我知道有角度的散列,并且我不想使用那些散列,我需要一些服务器配置。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
对于nginx,请尝试以下操作:How to redirect all Angular request to index.html in Nginx