AngularJS页面无法刷新的时候/共享一个环节的工作 [英] AngularJS page not working when refresh/share a link

查看:134
本文介绍了AngularJS页面无法刷新的时候/共享一个环节的工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网页,它的工作就好了。这个问题开始,当我需要刷新页面或尝试共享与他人的链接(甚至是在新标签中打开它)。

当我尝试这样做,该页面无法正常工作。它加载只页眉,页脚等,但不是在我的 NG-鉴于部分,也没有CSS类,等等...

另外,我使用的是HTML5模式AngularJS本code:

  $ locationProvider.html5Mode({
    启用:真
});
 

我试图通过.htaccess重新加载页面,它的工作,但只适用于第一个链接。例如 site.com/News 加载好了,但如果我尝试刷新/股的页面 site.com/News/4 (都到一个单独的新闻页面),那么它将无法工作了。

这是在使用了$ C $词我的.htaccess 文件

 < IfModule mod_rewrite.c>
    RewriteEngine叙述上
    的RewriteBase /
    的RewriteCond%{} REQUEST_FILENAME!-f
    的RewriteCond%{} REQUEST_FILENAME!-d
    重写规则^(。*)/index.html
< / IfModule>
 

解决方案

试试这个:

  RewriteEngine叙述上
的RewriteCond%{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
的RewriteCond%{DOCUMENT_ROOT}%{REQUEST_URI} -d
重写规则^  -  [L]
重写规则^ /index.html
 

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>

解决方案

Try this:

RewriteEngine On  
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
RewriteRule ^ /index.html

这篇关于AngularJS页面无法刷新的时候/共享一个环节的工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆