本文介绍了UI-Router:URL更改,但是视图未加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的路由器具有以下代码:

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('/');

}])

我的问题是training.show状态.我有这个链接:

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>

当我单击带有ui-sref"workouts.show({id: workout._id})"的链接时,URL会更改为正确的格式,并动态添加ID,但不会加载视图.它只是停留在同一页面上.

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.

在此先感谢您的帮助!

推荐答案

我遇到了类似的问题.您必须在锻炼"状态下拥有一个ui视图,以便您的"workouts.show"将作为孩子呈现.希望这会有所帮助.

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.

这篇关于UI-Router:URL更改,但是视图未加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 15:04