AngularJS路由之ui-router(三)大小写处理

一、ui-router 路由地址处理大小写

默认ui-router的state()方法指定路由配置对大小写敏感。

解决方案一:$urlRouterProvider服务的rule()  方法提供处理客户端连接的接口,

app.config(function ($urlRouterProvider) {
    // Here's an example of how you might allow case insensitive urls
    // Note that this is an example, and you may also use 
    // $urlMatcherFactory.caseInsensitive(true); for a similar result.
    $urlRouterProvider.rule(function ($injector, $location) {
        //what this function returns will be set as the $location.url
        var path = $location.path(), normalized = path.toLowerCase();
        if (path != normalized) {
            //instead of returning a new url string, I'll just change the $location.path directly so I don't have to worry about constructing a new url string and so a new state change is not triggered
            $location.replace().path(normalized);
        }
    });
});

这样处理,浏览器的地址栏总会显示小写,但是这是除了动态参数之外的部分。


相关文章:

https://github.com/angular-ui/ui-router/wiki/URL-Routing 

AngularJS 动态加载控制器实例-ocLoazLazy(二)

AngularJS路由之ui-router(二)

AngularJS路由之ui-router(一)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值