Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between --base-href and --deploy-url parameters of angular-cli tool

People also ask

What is -- BASE HREF Angular?

--base-href If you deploy your Angular app to a subfolder, the '--base-href' is important to generate the correct routes. This parameter will update the <base href> tag inside the index. html. For example, if the index. html is on the server at /angularapp/index.

Why do we need BASE HREF in Angular?

Angular makes use of the base href to tell router how to compose navigation URLs. If your application exists at the root, then you can use / as the href value as shown below.

What is base in Angular?

During navigation, the Angular router uses the base href as the base path to component, template, and module files. In development, you typically start the server in the folder that holds index. html . That's the root folder and you'd add <base href="/"> near the top of index.

What is dist folder in Angular?

The dist folder is the build folder which contains all the files and folders which can be hosted in the server. The dist folder contains the compiled code of your angular application in the format of JavaScript and also the required HTML and CSS files.


  • Base-href is being used by routing
  • deploy-url is for assets.

In most cases base-href is enough.

Please see these posts:

  • https://github.com/angular/angular-cli/issues/9835

  • https://shekhargulati.com/2017/07/06/angular-4-use-of-base-href-and-deploy-url-build-options/


To put my scripts inside the "/test/app1/script/" folder, I use this command:

ng build --prod --base-href /test/app1/ --deploy-url /test/app1/script/

Thus my app is accessible at https://example.com/test/app1/ but my JS scripts and CSS are in the https://example.com/test/app1/script/ directory.


If I want to use /users as my application base for the router and /public as a base for my assets.

ng build --prod --base-href /users --deploy-url /public 

See Shekhar Gulati's blog for a detailed example...