I have finished a development of Angular 2 application and I need to deploy it. I need it to work standalone. So, I tried to move the content of dist folder inside a new apache website, but the routing mechanism doesn't work for some reason, I am getting 404 error when I try to go to /integrations route, for example. During the development, on angular 2 server, /integrations works and Angular 2 routing mechanism works and displays the component without problem. I need the standalone app to also be able to work with different URLs/paths. Any suggestions?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Follow following steps :
Step 1:
ng build --prod --env=prod
Step 2. (Copy dist into server) then dist folder created, copy dist folder and deploy it in root directory of server.
Step 3. Creates .htaccess
file in root folder and paste this in the .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>
回答2:
Yes you need to follow the angular 2 documentation deployment
It explain you how to fallback to index.html and give you an example with apache