D
D
Drovosek012019-05-23 22:31:28
Angular
Drovosek01, 2019-05-23 22:31:28

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 buildand the dist folder with compiled files appeared in the root of the project:
5ce6f381a5c95437954071.png
I open index.html and a blank white page is displayed (although when the command was executed , the ng servemade 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).
5ce6f44a73409136263938.png
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">

But this did not give any positive results.
The browser tries to load .js files from the root of the drive.
Why is this happening and how to fix it?
UPDATE:
I dug into the html file, commented out the tag After that, all the files loaded without errors, but this tag is necessary for the application to work, the same blank page is displayed and an error pops up in Dev Tools<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.

5ce6fa8f65af0572228973.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Luzanov, 2019-05-23
@dmitry_luzanov

<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]/

S
Shohruh Shaimardonov, 2019-05-23
@joeberetta

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 question

Ask a Question

731 491 924 answers to any question