UI-Router: URL changes, but view is not loaded

馋奶兔 提交于 2019-12-13 01:59:08

问题


I have the following code for my router:

.config(['$stateProvider', '$urlRouterProvider', '$locationProvider', function($stateProvider, $urlRouterProvider, $locationProvider) {

  $stateProvider
    .state('main', {
      url: '/',
      templateUrl: 'templates/main.html',
      controller: 'MainCtrl'
    })
    .state('login', {
      url: '/login',
      templateUrl: 'templates/login.html',
    })
    .state('signup', {
      url: '/signup',
      templateUrl: 'templates/signup.html',
      controller: 'SignupCtrl'
    })
    .state('userEdit', {
      url: '/user/edit',
      templateUrl: 'templates/user/edit.html',
      controller: 'UserEditCtrl'
    })
    .state('workouts', {
      url: '/workouts',
      templateUrl: 'templates/workouts/index.html',
      controller: 'WorkoutsCtrl'
    })
    .state('workouts.show', {
      url: '/:id',
      templateUrl: 'show.html',
      controller: 'WorkoutCtrl',
      onEnter: function() {
        console.log('this is stupid');
      }
    })

    $urlRouterProvider.otherwise('/');

}])

My issue is with the workouts.show state. I have this link:

<div class="" ng-repeat="workout in workouts track by workout._id">
  <hr>
  <a ui-sref="workouts.show({id: workout._id})">{{ workout.shortURI }}</a>
  <p>{{ workout.description }}</p>
  <ul class="exercise-list">
    <li ng-repeat="exercise in workout.exercises">{{ exercise }}</li>
  </ul>
  <hr>
</div>

When I click on the link with ui-sref"workouts.show({id: workout._id})" the url changes to the proper format, and adds the id dynamically, but the view does not load. It just stays on the same page.

I have seen several other questions that are similar, but none of the accepted solutions have worked for me, and I have spent too long on this now.

Thanks in advance for any help!


回答1:


I had similar issue. You must have a ui-view in your "workouts" state, so that your "workouts.show" will render as a child. Hope this helps.



来源:https://stackoverflow.com/questions/32028180/ui-router-url-changes-but-view-is-not-loaded

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!