加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 角ui.router state.go(‘statename’)不工作

发布时间:2020-12-17 07:47:16 所属栏目:安全 来源:网络整理
导读:这是angular.ui.router的定义 app.config([ '$stateProvider','$urlRouterProvider',function($stateProvider,$urlRouterProvider){ $urlRouterProvider.otherwise('/'); $stateProvider.state('/login',{ url: "/",controller: 'Login',templateUrl: 'login
这是angular.ui.router的定义
app.config([
  '$stateProvider','$urlRouterProvider',function($stateProvider,$urlRouterProvider){
    $urlRouterProvider.otherwise('/');
      $stateProvider.state('/login',{
          url: "/",controller: 'Login',templateUrl: 'login.html'
      })
      .state('/useractivities',{
          url: "/activities",controller: 'activitiesController',templateUrl: 'useractivities.html'
      })
  }
]);

在登录控制器中,我正在执行

$state.go('useractivities',{});

这会导致错误“无法从状态’/’解析’useractivities’

我已经尝试了几件事情

$location.url('useractivities')

但没有运气,任何人都可以告诉我出了什么问题?

这里的问题是,$state.go()调用的参数必须是现有的状态名称.而“活动”不是现有的名称,它是’/ activities’

我首先建议使用不同的状态命名:

$stateProvider
  // instead of this
  // .state('/',{
  // let's use this state name      
  .state('login',{          // this is a STATE Name
      url: "/",templateUrl: 'login.html'
  })
  // instead of this
  // .state('/activities',{
  // use this
  .state('activities',{      // this is a STATE Name
      url: "/activities",templateUrl: 'useractivities.html'
  })

然后这将工作

$state.go('activities',{}); // we use STATE Name here
$state.go('login',{});      // also state name...

请查看这里了解更多详情:

$state.go(to [,toParams] [,options])

to

String Absolute State Name or Relative State Path

The name of the state that will be transitioned to or a relative state path. If the path starts with ^ or . then it is relative,otherwise it is absolute.

Some examples:

$state.go('contact.detail') will go to the 'contact.detail' state
$state.go('^') will go to a parent state.
$state.go('^.sibling') will go to a sibling state.
$state.go('.child.grandchild') will go to a grandchild state.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读