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

user2534381 picture user2534381 · Sep 15, 2013 · Viewed 20.5k times · Source

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.

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")
});

Answer

Quentin picture Quentin · Sep 15, 2013

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.

http://www.example.com/#foo and http://www.example.com/#!foo are different parts of the same page.

But http://www.example.com/#foo and http://www.example.com/!#foo are different pages altogether.