I want to first cite @MaximeMorin comment:
My experience with ./ has been very different. It works until the user navigates to a route and hit the browser's refresh button or keys. At that point, our rewrites handle the call, serves the index page, but the browser assumes that ./ is the current route not the web app's root folder. We solved the OP's issue with a dynamic (.aspx, .php, .jsp, etc) index which sets the base href.
This aligns with my experience. Using a ./ base href breaks page reloading when nested routes are used. However, at least for Apache and NGINX web servers, there is the SSI (Server Side Includes) option, which allows to dynamically adjust <base href="..."> tag without involving additional script engines.
Apache configuration sample
.htaccess (assuming the folder for angular app is <webroot>/prefix):
Options +Includes
<Files "index.html">
AddOutputFilter INCLUDES html
</Files>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /prefix/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [L]
</IfModule>
index.html (ap_expr syntax):
<head>
<!--#if expr="v('SCRIPT_NAME') =~ m#^(.*/)index\.html$# && $1 =~ /^(.*)$/" -->
<!--#set var="base" value="$0" -->
<!--#else -->
<!--#set var="base" value="/" -->
<!--#endif -->
<base href="<!--#echo var="base" -->">
...
index.html (legacy apache 2.2.x syntax):
<head>
<!--#if expr="$SCRIPT_NAME = /^(.*\/)index\.html$/" -->
<!--#set var="base" value="$1" -->
<!--#else -->
<!--#set var="base" value="/" -->
<!--#endif -->
<base href="<!--#echo var="base" -->">
...
NGINX configuration sample
nginx.conf snippet (assuming the folder for angular app is <webroot>/prefix):
location /prefix/ {
ssi on;
try_files $uri /prefix/index.html;
}
index.html:
<head>
<!--#if expr="$uri = /^(.*\/)index\.html\z/" -->
<!--#set var="base" value="$1" -->
<!--#else -->
<!--#set var="base" value="/" -->
<!--#endif -->
<base href="<!--# echo var="base" -->">
...
Note that I'm using the \z PCRE token instead of $ in the above regex. The Nginx SSI engine will interpret $ as a variable name, throwing the error
invalid variable name in "^(.*\/)index\.html$" while sending response to client...
Unfortunately, these snippets can't be used in the src/index.html template as-is. Angular's HTML parser isn't SSI-aware, and the <base href="<!--# echo var="base" -->"> tag will be completely broken by the ng build process, so some post-build index.html patching will be required.