这是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’
原文链接:https://www.f2er.com/angularjs/143114.html我首先建议使用不同的状态命名:
$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.