解决办法原文地址: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(teral">true);
teral">这样设置之后url中确实是没有#号了,但又有一个新的问题出现了:从http://localhost:8000/view1跳转到http://localhost:8000/view2时一切正常,当刷新view1页面或者直接输入URL地址http://localhost:8000/view1后会出现404问题,那么这个问题该如何解决呢?
teral">解决办法原文地址:https://blog.csdn.net/weixin_36185028/article/details/72179568
teral">1、app.js中设置$locationProvider.html5Mode(teral">true);
3、静态网站
编辑Nginx的配置文件Nginx.conf,增加try_files配置。
动态网站
动态网站,一般不是通过Nginx直接路由,而是通过Web服务器管理路由。假设我们使用的是Node.js的Express的Web框架。打开Express框架的路由访问控制文件server.js,增加路由配置。
}</span><span style="color: #0000ff">else</span>{ <span style="color: #008000">//</span><span style="color: #008000">angular<a href="https://www.jb51.cc/tag/qidongye/" target="_blank" class="keywords">启动页</a></span>
res.sendfile(<span style="color: #800000">'</span><span style="color: #800000">app/index.html</span><span style="color: #800000">'</span><span style="color: #000000">);
}
});
设置当 站内路径(req.path) 不包括 /api 时,都转发到 AngularJS的ng-app(index.html)。所以,我们再直接访问地址 (http://onbook.me/book)时,/book 不包括 /api,就会被直接转发到AngularJS进行路由管理.