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

use*_*381 3 javascript jquery hashbang angularjs

我想将url显示为"www.test.com/!#",因为我正在使用$ locationProvider.hashPrefix("!"); 但它显示网址为"www.test.com/#!" .我想要 "!" 哈希之前不哈希.

谢谢

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")
});
Run Code Online (Sandbox Code Playgroud)

Que*_*tin 7

如果您想!在片段标识符开始之前使用URL,那么您需要将其放在URL中以开始,而不是尝试使用Angular.

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

但是,http://www.example.com/#foo并且http://www.example.com/!#foo完全是不同的页面.

  • 不,没有. (3认同)