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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 13:18:50  来源:igfitidea点击:

Angularjs : $locationProvider.hashPrefix("!") ;

javascriptjqueryangularjshashbang

提问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/#fooand http://www.example.com/#!fooare different parts of the same page.

http://www.example.com/#foo并且http://www.example.com/#!foo是同一页面的不同部分。

But http://www.example.com/#fooand http://www.example.com/!#fooare different pages altogether.

但是http://www.example.com/#foohttp://www.example.com/!#foo是完全不同的页面。