How to set “default page” for Angular in Azure Web App on Linux service plan

旧巷老猫 提交于 2019-12-11 18:43:25

问题


I can deploy Angular to Azure Web Apps on Linux service plan and it works fine when hitting {myapp}.azurewebsites.net/index.html

I can navigate inside the app as expected.

When hitting the root {myapp}.azurewebsites.net it just displays the hostingstart.html.

It does not help to remove the hostingstart.html as suggested in some articles.

If I try to hit a sub page url directly (like {myapp}.azurewebsites.net/mypage) then I get an error : Cannot GET /mypage (this works when I run locally)

I suspect that i need to setup a default page, but i cannot find this anywhere in the Application Settings in the Azure Web App. (I think this is only available on Windows service plans - not on Linux Service Plans).

How do i deploy properly to Linux App Service for this to work ?

I have found a lot of articles on the issue, but they all seem to cover Windows App Service Plan.


回答1:


You need to add URL rewrite rules to the Apache server so that any page request gets redirected to Angular's index.html

Paste this into your root .htaccess file:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.html [L]
</IfModule>

(Source: https://github.com/angular/angular/issues/11884#issuecomment-288852433)

EDIT: If using a node.js backend, see this SO answer for reference: https://stackoverflow.com/a/34864585/235648



来源:https://stackoverflow.com/questions/53304385/how-to-set-default-page-for-angular-in-azure-web-app-on-linux-service-plan

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!