我试图在angular.js中实现单页应用程序。
我找到了一个演示
http://scotch.io/demos/angular-single-page-routing
这很好
但我注意到http://scotch.io/demos/angular-single-page-routing#/contact
每个url中都有#标记
我们能不能像http://scotch.io/demos/angular-single-page-routing/a/contact那样
在这里可以扮演#的角色
有什么想法吗?
谢谢
发布于 2014-12-22 05:18:59
正如New通过Docs链接所指出的,对于单个页面应用程序,有两种方法可以按角度进行路由。
一种方法涉及到hashbang,它更易于跨浏览器移植,还允许您对条目进行书签。另一种方法是使用HTML5模式,它将直接操作历史对象。它需要角在页面上是活动的,因此你不能书签它。这就是你所要求的方法。
要实现它,您需要$locationProvider.html5Mode(true);
这是直接从角的角度,新开发链接的文档在他的评论(https://docs.angularjs.org/guide/$location#hashbang-and-html5-modes)。
function($locationProvider) {
$locationProvider.html5Mode(true);
$locationProvider.hashPrefix('!');
},
发布于 2014-12-22 08:05:35
您需要更改ul类中的某些内容,但是代码中没有问题,除非href导航添加到使用#确定的代码中,在类nav navbar nav导航栏-右about.html _ contact.html中更改下面的href,删除href中的散列#。您不需要将页面转换为新的扩展,但是如果要将页面contact.html移动到名为(a)的新文件夹,则返回到源代码,将href实现为/contact.html
https://stackoverflow.com/questions/27596769
复制相似问题