1

I am new to Angular2 Wep app development.

I created one Angular2 app with use of angular-cli, now i want to deploy this app to my tomcat server.

I gave ng build and it create the dist folder for deployment. I copied all files inside the dist folder and create one folder inside the Tomcat webapps folder like somename and paste all files inside this somename folder. And i changed the index.html base href as /somename.

<base href="/somename">

if i run the app from server like localhost:9000/somename. it gives the error in console like file not error.

How can i solve the issue.

please help me, thanks in advance.

2
  • 1
    Please add the exact error message to your question. What server are you using? Does it work on the server in the root path? Have you tried using HashLocationStrategy? (imports: [RouterModule.forRoot(myRoutes, {useHash: true})])? Commented Mar 15, 2017 at 8:45
  • please check this link stackoverflow.com/questions/39018765/… Commented Mar 17, 2017 at 5:41

2 Answers 2

3

Try setting base href as one of the following:

<base href="./">: This usually works well for starter packs, or beginner projects that do not have/use Angular Routers. It basically sets the base as whichever directory it is served from.

<base href="/somename/> (Note the ending /): This worked well for me on IIS 8.5 -- more details here.

Also, on a related note, a minor piece of advise would be to use ng build --base-href your-new-base-href command instead of manually editing index.html everytime you build your app.

Sign up to request clarification or add additional context in comments.

1 Comment

Just for the heck of it... you can further experiment with different values of base href, like "/", "", "somename", "somename/", "./", "./somename". It will give you a decent, practical understanding of how <base> works. Quick info on base tag: w3schools.com/tags/tag_base.asp
1

Try to build app like

ng build --base-href /myApp/

or

<base href="/myApp/">

Your dist folder content should be copied to "myApp" folder. Run the app from tomcat server like localhost:8080/myApp/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.