Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NG Serve with a VirtualPath or subdirectory

We run our angular application in IIS as a virtual application "myapplication"

In our angular app I have set in index.html:

<base href="/myapplication/"> 

It is working in IIS fine. However now NG serve does not work. As it can't find all the bundles under http://localhost/myapplication/ because the CLI isn't running under that path.

I have tried

ng serve --base-href /myapplication/

and browse to http://localhost:4200/myapplication/

I still see the same errors.

How do I tell the CLI to serve the application under "http://localhost:4200/myapplication/"?

like image 365
twaldron Avatar asked Oct 18 '25 11:10

twaldron


1 Answers

Change the base href to just this:

<base href="/">

That sets the default for development time.

Then when you build for production, use:

ng serve --base-href /myapplication/

That will set it correctly when it builds the files for deployment.

like image 107
DeborahK Avatar answered Oct 20 '25 01:10

DeborahK



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!