Bad base path when updating browser, ngView breaks

When I access my page from the index and start browsing, everything works fine, but when I am on a route other than / , for example, in /details/123 , and I refresh the page (I have URL rewriting configured) the route is not set correctly .
This means that when I check the location path in normal browsing from the index, and I am in /details/123 , the location path /details/123 is as expected, but when I refresh the page and I'm still on /details/123 , the location path changes to /123 , causing ngView to display the wrong view.
I am using html5 mode and Angular v.1.1.5

UPDATE: I created a simple example here to illustrate the problem.
I do not have a special setting, I do not think that this is a problem with the server. I have the same problem with another python application where the redirection is done inside the application.
.htaccess :

 <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*) /index.php </IfModule> 
+4
source share
1 answer

This may be due to an unpleasant problem that appeared during Angular 1.1.5 and is a bug in the main library. A solution that worked for many is to add the following tag to head.html.

If your application is running in the root directory of your domain.

 <head> ... <base href="/"></base> ... </head> 

Or, if your application is running in a subdirectory, specify this subdirectory (for example, "myapp"):

 <head> ... <base href="/myapp/"></base> ... </head> 

In addition, you can also try a new set of rewriting rules. This configuration works for many ui-router users.

 <IfModule mod_rewrite.c> RewriteEngine on # Don't rewrite files or directories RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ - [L] # Rewrite everything else to index.html to allow html5 state links RewriteRule ^ index.html [L] </IfModule> 
+8
source

Source: https://habr.com/ru/post/1493520/


All Articles