javascript Angularjs : $locationProvider.hashPrefix("!") ;
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18811003/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Angularjs : $locationProvider.hashPrefix("!") ;
提问by user2534381
I want to show url as "www.test.com/!#" for that i am using $locationProvider.hashPrefix("!") ; but it shows url as "www.test.com/#!" . i want "!" before hash not after hash.
我想将 url 显示为 "www.test.com/!#" 因为我正在使用 $locationProvider.hashPrefix("!") ;但它显示网址为“www.test.com/#!” . 我想要 ”!” 在哈希之前而不是在哈希之后。
Thanks
谢谢
var app = angular.module('app', []);
app.config(function ($routeProvider, $locationProvider) {
$locationProvider.html5Mode(false);
$locationProvider.hashPrefix("!");
$routeProvider.when('/', {
templateUrl: "app.html",
controller: "AppCtrl"
}
)
.when('/Program', {
templateUrl: "detail1.html",
controller: "Redirect"
})
.when('/Program/123456/channel/78458585',
{
templateUrl: "details.html",
controller: "Detail"
});
});
app.controller("AppCtrl", function ($scope) {
});
app.controller("Detail", function ($scope, $location) {
});
app.controller("Redirect", function ($scope, $location) {
$location.path("/Program/123456/channel/78458585")
});
回答by Quentin
If you want a !
in the URL before the fragment identifier begins, then you need to put it in the URL to start with and not try to do it with Angular.
如果您希望!
在片段标识符开始之前在 URL 中使用a ,那么您需要将它放在 URL 中开始,而不是尝试使用 Angular 来做。
http://www.example.com/#foo
and http://www.example.com/#!foo
are different parts of the same page.
http://www.example.com/#foo
并且http://www.example.com/#!foo
是同一页面的不同部分。
But http://www.example.com/#foo
and http://www.example.com/!#foo
are different pages altogether.
但是http://www.example.com/#foo
和http://www.example.com/!#foo
是完全不同的页面。