$routeProvider 不适用于 html5Mode [英] $routeProvider not working with html5Mode
本文介绍了$routeProvider 不适用于 html5Mode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚刚开始学习 angularJs,并尝试使用 angular 路由服务配置部分页面.
I just start to learn angularJs, and was trying to configure the partial page with angular route service.
它适用于散列格式,但是,当我试图摆脱散列时,routeProvider 停止工作.
It worked with the hash format, however,when I tried to get rid of hash, the routeProvider stopped working.
JS
app.config(function($routeProvider,$locationProvider){
$locationProvider.html5Mode(true);
$routeProvider.when("/", { templateUrl: "/index.html" }).
when("/about", { templateUrl: "/partials/about.html" }).
when("/contact", { templateUrl: "/partials/contact.html" }).
otherwise({ redirectTo: '/' });
});
HTML
<ul class="nav navbar-nav navbar-right">
<li><a href="/about">About</a></li>
<li><a href="/contact">Contact</a></li>
</ul
有人能指教我吗?
推荐答案
尝试改变
$locationProvider.html5Mode(true);
到
$locationProvider.html5Mode(true).hashPrefix('!');
并添加
<base href="/">
在文档head"部分.
in a document "head" section.
这篇关于$routeProvider 不适用于 html5Mode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文