加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs中URL中的#号问题,$locationProvider.html5Mode(true)

发布时间:2020-12-17 10:39:49 所属栏目:安全 来源:网络整理
导读:解决办法原文地址:https://blog.csdn.net/weixin_36185028/article/details/72179568 angularjs支持两种url模式,hash模式和html5模式 默认是hash模式,在hash模式下url中有#,例如:http://localhost:9090/#/cases/all html5模式下url中是没有#的, 如何设

解决办法原文地址:https://blog.csdn.net/weixin_36185028/article/details/72179568

angularjs支持两种url模式,hash模式和html5模式

默认是hash模式,在hash模式下url中有#,例如:http://localhost:9090/#/cases/all

html5模式下url中是没有#的,

如何设置html5模式呢?

$locationProvider.html5Mode(

元素内添加标签

3、静态网站

编辑nginx的配置文件nginx.conf,增加try_files配置。

$htdocs /www/deploy/mysite/// /index.html =

动态网站

动态网站,一般不是通过Nginx直接路由,而是通过Web服务器管理路由。假设我们使用的是Node.js的Express的Web框架。打开Express框架的路由访问控制文件server.js,增加路由配置。

(req.path.indexOf()>=}</span><span style="color: #0000ff"&gt;else</span>{ <span style="color: #008000"&gt;//</span><span style="color: #008000"&gt;angular启动页</span> res.sendfile(<span style="color: #800000"&gt;'</span><span style="color: #800000"&gt;app/index.html</span><span style="color: #800000"&gt;'</span><span style="color: #000000"&gt;); }

});

设置当 站内路径(req.path) 不包括 /api 时,都转发到 AngularJS的ng-app(index.html)。所以,我们再直接访问地址 (http://onbook.me/book)时,/book 不包括 /api,就会被直接转发到AngularJS进行路由管理.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读