尝试使用stateHelper重新组织应用的菜单布局后,我收到了错误消息;
Error: Could not resolve 'app.user.home' from state ''
at Object.transitionTo (ionic.bundle.js:49177)
at Object.go (ionic.bundle.js:49110)
at app.js:220
当我的应用加载且$state.go('app.user.home')
在app.js上运行时会发生这种情况:220
我的情况是管理员用户会看到"汉堡包#34;图标打开包含特定视图的侧边菜单,只有管理员可以导航到。
当非管理员进入同一视图时,会显示一个" home"而是链接到主视图的图标。
管理员和非管理员都拥有主视图,其中ui-sref
个链接指向他们可以导航到的其他视图。
当"汉堡包图标"为管理员显示主页视图的ui-sref
被移动到侧边菜单。
这是我的stateHelperProvider
代码;
.config(function(stateHelperProvider, $urlRouterProvider, $ionicConfigProvider) {
stateHelperProvider
.state({
name: 'app',
url: '/',
abstract: true,
templateUrl: 'templates/menu.html',
controller: 'MenuCtrl',
})
.state({
name: 'app.user',
url: '/user',
abstract: true,
children:[
{
name: 'app.user.home',
url: '/home',
templateUrl: 'templates/landing.html',
controller: 'HomeCtrl'
},
{
name: 'app.user.board',
url: '/board',
templateUrl: 'templates/pta-board.html',
controller: 'BoardCtrl'
},
{
name: 'app.user.events',
url: 'events',
templateUrl: 'templates/events.html',
controller: 'EventsCtrl'
},
{
name: 'app.user.chatrooms',
url: '/chat-rooms',
templateUrl: 'templates/chat-rooms.html',
controller: 'RoomsCtrl',
children:[
{
name: 'app.user.chatrooms.chatroom',
url: '/room',
templateUrl: 'templates/chat-room.html',
params:{
roomId: null,
chatters: null
},
controller: 'ChatCtrl'
}
]
},
{
name: 'app.user.profile',
url: '/profile',
templateUrl: 'templates/user-profile.html',
params:{
isNewUser: null
},
controller: 'UserCtrl'
},
{ name: 'app.user.admin',
url: 'admin',
abstract: true,
children:[
{
name: 'app.user.admin.calendar',
url: '/calendar',
params:{
selectedEvent: null,
calendarTitle: 'Volunteer',
isVolunteerSignup: true
},
templateUrl: 'templates/rcalendar.html',
controller: 'CalendarCtrl'
},
{
name: 'app.user.admin.volunteers',
url: '/volunteers',
params:{
thisHoursVolunteers: null,
thisEvent: null
},
templateUrl: 'templates/admin-interact.html',
controller: 'VolunteerCtrl'
},
{
name: 'app.user.admin.roles',
url: '/roles',
templateUrl: 'templates/roles.html',
controller: 'RoleCtrl'
},
{
name: 'app.user.admin.settings',
url: '/settings',
templateUrl: 'templates/settings.html',
controller: 'SettingsCtrl'
}
]
}
]
})
.state({
name: 'login',
url: '/login',
templateUrl: 'templates/login.html',
controller : 'LoginCtrl'
})
.state({
name: 'signup',
url: '/signup',
templateUrl: 'templates/signup.html',
controller : 'SignupCtrl'
});
// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise('/home');
$ionicConfigProvider.scrolling.jsScrolling(false);
});
我的侧边菜单,menu.html,模板;
<ion-side-menus enable-menu-with-back-views="false">
<ion-side-menu-content>
<ion-nav-bar ng-class="{'has-subject': subject}"
class="white-font bar-header bar-positive">
<!-- <ion-nav-back-button></ion-nav-back-button> -->
<ion-nav-buttons side="left" >
<button ng-if="$root.isAdmin" class="button button-icon button-clear ion-navicon" menu-toggle="left">
</button>
<button ng-if="!$root.isAdmin" class="button button-icon button-clear ion-home" ui-sref="app.user.home">
</button>
</ion-nav-buttons>
</ion-nav-bar>
<ion-nav-view></ion-nav-view> <!-- ionic's equivalent to ui-view -->
</ion-side-menu-content>
<ion-side-menu class="side-menu" width="140" side="left">
<ion-header-bar class="white-font bar-header bar-positive">
<h1 class="title">Admin Menu</h1>
</ion-header-bar>
<ion-content>
<ion-list>
<ion-item menu-close>
<a class="button button-block button-clear button-dark" ui-sref="app.user.admin.calendar({ calendarTitle: 'Calendar', isVolunteerSignup: false })">Calendar</a>
</ion-item>
<ion-item menu-close>
<a class="button button-block button-clear button-dark" ui-sref="app.user.admin.roles">Roles</a>
</ion-item>
<ion-item menu-close>
<a class="button button-block button-clear button-dark" ui-sref="app.user.home">Main Menu</a>
</ion-item>
<ion-item menu-close>
<a class="button button-block button-clear button-dark" ui-sref="app.user.admin.settings">School Settings</a>
</ion-item>
</ion-list>
</ion-content>
</ion-side-menu>
</ion-side-menus>
然后是我的家庭观点;
<ion-view class="landing" title="{{school.name}}">
<div ng-if="school.logo" class="tall bar bar-header">
<img class="school-logo" ng-src="{{school.logo}}" >
</div>
<ion-content ng-class="{'has-tall-header': school.logo}">
<ion-list class="nav-buttons">
<ion-item>
<a class="button button-block button-clear button-dark" ui-sref="app.user.board">
PTA Board
<i class="icon ion-board"></i>
</a>
</ion-item>
<ion-item>
<a class="button button-block button-clear button-dark" ui-sref="app.user.events">
Events
<i class="icon ion-calendar"></i>
</a>
</ion-item>
<ion-item>
<a class="button button-block button-clear button-dark" ui-sref="app.user.rooms">
Chat
<i class="icon ion-chatboxes"></i>
</a>
</ion-item>
<ion-item>
<a class="button button-block button-clear button-dark" ui-sref="app.user.profile">
Profile
<i class="icon ion-android-user-menu"></i>
</a>
</ion-item>
<ion-item>
<a class="button button-block button-clear button-dark" ng-click="logout()">
Logout
<i class="icon ion-log-out"></i>
</a>
</ion-item>
</ion-list>
</ion-content>
</ion-view>
答案 0 :(得分:0)
发生此错误是因为我要求的状态未注册。我能够通过更新stateHelper代码中的状态名称属性来修复错误,以便它们不包含其父级的点表示法,如此处所示。
.config(function(stateHelperProvider, $urlRouterProvider, $ionicConfigProvider) {
stateHelperProvider
.state({
name: 'app',
url: '/app',
abstract: true,
templateUrl: 'templates/menu.html',
controller: 'MenuCtrl',
children: [
{
name: 'user',
url: '/user',
abstract: true,
template: '<ion-nav-view></ion-nav-view>',
children:[
{
name: 'home',
url: '/home',
templateUrl: 'templates/landing.html',
controller: 'HomeCtrl'
},
{
name: 'board',
url: '/board',
templateUrl: 'templates/pta-board.html',
controller: 'BoardCtrl'
},
{
name: 'events',
url: '/events',
templateUrl: 'templates/events.html',
controller: 'EventsCtrl'
},
{
name: 'chatrooms',
url: '/chat-rooms',
templateUrl: 'templates/chat-rooms.html',
controller: 'RoomsCtrl',
children:[
{
name: 'room',
url: '/room',
params:{
roomId: null,
chatters: null
},
templateUrl: 'templates/chat-room.html',
controller: 'ChatCtrl'
}
]
},
{
name: 'profile',
url: '/profile',
params:{
isNewUser: null
},
templateUrl: 'templates/user-profile.html',
controller: 'UserCtrl'
}
]
},
{
name: 'admin',
url: '/admin',
abstract: true,
template: '<ion-nav-view></ion-nav-view>',
children:[
{
name: 'calendar',
url: '/calendar',
params:{
selectedEvent: null,
calendarTitle: 'Volunteer',
isVolunteerSignup: true
},
templateUrl: 'templates/rcalendar.html',
controller: 'CalendarCtrl'
},
{
name: 'volunteers',
url: '/volunteers',
params:{
thisHoursVolunteers: null,
thisEvent: null
},
templateUrl: 'templates/admin-interact.html',
controller: 'VolunteerCtrl'
},
{
name: 'roles',
url: '/roles',
templateUrl: 'templates/roles.html',
controller: 'RoleCtrl'
},
{
name: 'settings',
url: '/settings',
templateUrl: 'templates/settings.html',
controller: 'SettingsCtrl'
}
]
}
]
})
.state({
name: 'login',
url: '/login',
templateUrl: 'templates/login.html',
controller : 'LoginCtrl'
})
.state({
name: 'signup',
url: '/signup',
templateUrl: 'templates/signup.html',
controller : 'SignupCtrl'
});
我仍然无法导航到board
,events
,chatrooms
或profile
州,但我不会再遇到任何错误。 admin
孩子和所有其他州,包括home
,奇怪的是,按预期工作。