简体   繁体   中英

How to deploy Angular 2 application as a standalone (using dist folder)

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?

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>

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM