问题
I have a webpage and it's working just fine. The problem starts when i need to refresh the page or try to share a link with someone (or even open it in a new tab).
When i try to do it, the page doesn't work. It loads only the header, footer, etc. But not the part inside my ng-view and also no css class, etc...
Also, I'm using html5 mode in AngularJS with this code:
$locationProvider.html5Mode({
enabled:true
});
I tried to use a .htaccess to reload the page and it's working, but only for the first link. For example site.com/News is loading ok, but if I try to refresh/share the page site.com/News/4 (which goes to an individual news page) then it won't work anymore.
This is the code i used in my .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) /index.html
</IfModule>
回答1:
Try this:
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
RewriteRule ^ /index.html
来源:https://stackoverflow.com/questions/31340154/angularjs-page-not-working-when-refresh-share-a-link