AngularJS UI路由器,否则陈述,而不是网址是什么? [英] AngularJS ui-router otherwise to state instead of url?

查看:113
本文介绍了AngularJS UI路由器,否则陈述,而不是网址是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 AngularJS UI -router 并在我的 app.js 。我有以下行:

I am using AngularJS and ui-router and in my app.js. I have the following line:

$urlRouterProvider.otherwise('/');

然而我不希望它给用户发送到网址,但而不是以状态

.state('404',
        {
            views: {
                'body': {
                    templateUrl: 'partials/404.html',
                }
            }
        });

一般情况下我只是这样做:

Normally I would just do this:

$state.go('404');

我怎么能做到这一点的,否则的方法?

How can I do this for the otherwise method?

注:我的404的状态并没有一个URL,所以基本上保留了用户进入或访问,只是改变了模板中的网址

推荐答案

我觉得你实现了这个code

I think you achieved that with this code

$urlRouterProvider.otherwise(function($injector, $location){
  $injector.invoke(['$state', function($state) {
    $state.go('404');
  }]);
}); 

这篇关于AngularJS UI路由器,否则陈述,而不是网址是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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