Issue
I'm running an Angular2 application inside of a spring boot app. This is my structure currently:
src/main
java/com/test
Application.java
resources/static
app/
css/
images/
node_modules/
index.html
package.json
systemjs.config.js
tsconfig.json
I can't for the life of me figure out how to tell Angular that I'm serving it from a path like so: localhost:8080/angularApp
I've got it configured on the spring side of things:
system.context-path=/angularApp
but I can't get the App to actually recognize that. Here are a couple of the things I tried:
Inside of the tsconfig.json:
"baseUrl": "./angularApp
Also inside of tsconfig.json:
"paths": {
"app/*": [ "angularApp/app/*" ]
}
But neither of those are working.
when I try and load localhost:8080/angularApp
The issue I'm seeing is this:
GET http://localhost:8080/css/styles.css 404 ()
Inside of my index.html I've got it configured like this:
<link rel="stylesheet" href="css/styles.css">
If I configure it like this it does work, however that path may change based on the environment I'm running it in so hard coding every line like this isn't feasible:
<link rel="stylesheet" href="angularApp/css/styles.css">
I feel like this is supposed to be easy and I'm missing something.
Can anyone provide some insight?
Solution
You will need to add a base tag to the head of your index.html
<base href="/angularApp/">
Link to the docs for further explanation if needed: https://angular.io/guide/router#base-href
Answered By - dmungin
Answer Checked By - Senaida (JavaFixing Volunteer)