New to Angular. App works fine if deployed in nginx /var/www/mydomain.com/html. But I want to deploy it in /var/www/mydomain.com/html/myapp folder. I setup nginx available sites to this folder and index.html works fine. But relative paths in Angular app (e.g., images/mypic.png) being attempted to be retrieved from /var/www/mydomain.com/html/images folder (hence 404 error code) instead of /var/www/mydomain.com/html/myapp/images folder. How do I set a url prefix /myapp globally in Angular so all relative paths have this prefix. I have seen some answers here but they require changes in the component code. Isn't there a way to made this setting at deployment time so the same dist can be deployed in any path?
-
You can configure the path in angular.json or angular-cli.json file. Give your path for key "outputPath". eg: "outputPath": "myapp"lifetimeLearner007– lifetimeLearner0072018-06-16 15:13:17 +00:00Commented Jun 16, 2018 at 15:13
-
Take a look at this answer.Martin Parenteau– Martin Parenteau2018-06-16 15:40:24 +00:00Commented Jun 16, 2018 at 15:40
-
Yes that seems like the only choice. I was hoping I could make that change in the dist after build. Thanks.Allen King– Allen King2018-06-16 15:43:04 +00:00Commented Jun 16, 2018 at 15:43
-
If you use Webpack, this plugin appears to work.Martin Parenteau– Martin Parenteau2018-06-16 16:31:38 +00:00Commented Jun 16, 2018 at 16:31
-
Did you try setting proper baseRef in index.html or angular.json? It has to be set properly in order for assets to load.kashpatel– kashpatel2018-06-16 16:32:02 +00:00Commented Jun 16, 2018 at 16:32
Add a comment
|
2 Answers
###On angular.json > build > options configuration add this line with target sub directory
"baseHref" : "/v2/",
**like this **
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"baseHref" : "/v2/",
1 Comment
Brian White
Option
deployUrl is now deprecated. (See stackoverflow.com/questions/71695674/…)Use the following command, here /myapp/ is the relative path to the root site.
ng build --prod --base-href /myapp/
1 Comment
Oleg
Great - make sure to include the leading and lagging '/' around your subfolder otherwise it may lead to weird routing behaviours