I have an application on Angular 2 . All static URLs in this application begin with / (which is obvious). For example, my company is located at url /app/register/register.component.js/ and I can find it, for example, http://localhost:3000/app/register/register.component.js .

I want to make the url begin with some word, for example, front , and then the file path goes. The path above should look like this: http://localhost:3000/front/app/register/register.component.js . The location of the folders in the project should be the same.

  • Does it make sense to do this? - MihailPw

1 answer 1

Try to add to index.html

 <head><base href="/front/"></head> 
  • Made. When I try to access http://localhost:3000/front/ search takes place in the front folder, which I don’t have. - faoxis
  • And what serves statics on the server? (nginx, dev-server (webpack) or something else?) - Ruslan Masgutov
  • If you still do not want to change directories, you will have to register how to give the server data by URI / front / **. For example for nginx`a register the desired location - Ruslan Masgutov
  • I use nginx with this config: server { listen 80; access_log /var/log/nginx.access_log; error_log /var/log/nginx.error_log; location / { root /app/; } } server { listen 80; access_log /var/log/nginx.access_log; error_log /var/log/nginx.error_log; location / { root /app/; } } server { listen 80; access_log /var/log/nginx.access_log; error_log /var/log/nginx.error_log; location / { root /app/; } } - faoxis
  • Do you suggest replacing / with /front/ ? And then how can I still correct the npm settings so that when debugging and debugging through npm start everything works? - faoxis