目前,我在网页主机上刷新页面时出现问题,它始终显示未找到的路径。在互联网上搜索时,我找到了一个使用Hashlocation策略的解决方案:
RouterModule.forRoot(routes, {
useHash: true // add's #/ hash tag to URL
}),
问题是,如何在网络托管上使用相同的路由,没有哈希的网址,并确保页面可以刷新?
答案 0 :(得分:0)
当我在主机上使用apache时,解决方案非常简单。 我在我的网站根目录中创建了一个.htaccess文件,其中包含以下内容:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
它将指出所有其他路由返回索引html,角度路由将能够正确处理它。
注意:请确保您在index.html
中有头标记