Angularjs:$ locationProvider.hash preFIX;(""!) [英] Angularjs : $locationProvider.hashPrefix("!") ;

查看:451
本文介绍了Angularjs:$ locationProvider.hash preFIX;(""!)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要显示的URL为www.test.com/!#对于我使用$ locationProvider.hash preFIX(!);但它显示的网址为www.test.com/#! 。我想要 !散列之前,没有散了。

感谢

  VAR应用= angular.module('应用',[]);
的app.config(函数($ routeProvider,$ locationProvider){
    $ locationProvider.html5Mode(假);
    $ locationProvider.hash preFIX(!);
    $ routeProvider.when('/',{
        templateUrl:app.html
        控制器:AppCtrl
    }    )
        。当('/程序',{
        templateUrl:detail1.html
        控制器:重定向
    })
        。当('/程序/ 123456 /渠道/ 78458585',    {
        templateUrl:details.html
        控制器:详细信息
    });
});app.controller(AppCtrl功能($范围){});app.controller(详细信息,功能($范围,$位置){});app.controller(重定向功能($范围,$位置){
    $ location.path(/程序/ 123456 /渠道/ 78458585)
});


解决方案

如果你想有一个在URL中的片段标识符开始之前,你需要把它在URL中开始,而不是试图用角来做到这一点。

http://www.example.com/#foo http://www.example.com/#!foo 在同一页的不同部分。

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

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

解决方案

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.

这篇关于Angularjs:$ locationProvider.hash preFIX;(""!)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆