Answer the question
In order to leave comments, you need to log in
Why don't relative paths work in html file?
Made a small web application in Angular 6. after compilation, this is a set of html, css, js and assets, I decided to try to put it on github pages.
I executed the command in the VSCode terminal ng build
and the dist folder with compiled files appeared in the root of the project:
I open index.html and a blank white page is displayed (although when the command was executed , the ng serve
made content was displayed). I climbed into Dev Tools, and there errors are displayed that js files were not found (although they are in the same folder with the html file).
I tried in the html file in the script tag in the src attribute before the file names add "/", then "./", so that it turns out like this
<script type="text/javascript" src="/runtime.js">
<script type="text/javascript" src="./runtime.js">
<base href="/"/>
Error: No base href set. Please provide a value for the APP_BASE_HREF token or add a base element to the document.
Answer the question
In order to leave comments, you need to log in
<base href="https://[username].github.io/[repo]/">
This can be changed at build by specifying in a special flag:
ng build --prod --base-href https://[username].github.io/[repo]/
I ran into the same problem a couple of days ago, and the solution turned out to be this:
How I came to this:
Try to prescribe paths in different ways and in devtoolz point to the error itself with
It will show the full path where the file is looking for, in fact, dance from this.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question