We are running into an issue with properly displaying the pages for Angular routes served using Nginx. In our Angular project, our base href is "/dashboard". The project has two different routes pointing at "/dashboard/data-analysis" and "/dashboard/data-visual".
Here is my basic nginx.conf file:
server{
listen 80;
server_name localhost;
location /dashboard/ {
alias C:/Users/C123/Desktop/html/dashboard;
index index.html;
try_files $url $url/ /dashboard/index.html;
}
}
When I go on "localhost/dashboard/" or "localhost/dashboard/data-analysis", either pages will load the index.html from "C:/Users/C123/Desktop/html/dashboard/", but then fail to load "polyfill.js" "runtime.js" "style.js", etc. as defined in the <script>
tag of the index.html.
Moreover Nginx attempts to load those files from "C:/Users/C123/nginx/nginx-1.16.1/html/" instead of my alias (C:/Users/C123/Desktop/html/dashboard).
Is there a way I can define within the "dashboard/" location block where it will read everything from the index.html of my alias? I do not want to define the root outside, or a secondary location block for ".js" files only either.
UPDATE (this solution worked for me):
server{
listen 80;
server_name localhost;
location /dashboard/ {
root C:/Users/C123/Desktop/html/
try_files $uri $uri/ /dashboard/index.html/
}