UI-Router:URL 更改,但未加载视图 [英] UI-Router: URL changes, but view is not loaded

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

问题描述

我的路由器有以下代码:

.config(['$stateProvider', '$urlRouterProvider', '$locationProvider', function($stateProvider, $urlRouterProvider, $locationProvider) {$stateProvider.state('main', {网址:'/',templateUrl: 'templates/main.html',控制器:'MainCtrl'}).state('登录', {网址:'/登录',templateUrl: 'templates/login.html',}).state('注册', {网址:'/注册',templateUrl: 'templates/signup.html',控制器:'SignupCtrl'}).state('用户编辑', {网址:'/用户/编辑',templateUrl: 'templates/user/edit.html',控制器:'UserEditCtrl'}).state('锻炼', {网址:'/锻炼',templateUrl: 'templates/workouts/index.html',控制器:'锻炼控制'}).state('workouts.show', {网址: '/:id',templateUrl: 'show.html',控制器:'锻炼控制',onEnter:函数(){console.log('这太蠢了');}})$urlRouterProvider.otherwise('/');}])

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

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

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

我已经看到了其他几个类似的问题,但没有一个公认的解决方案对我有用,而且我现在在这方面花了太长时间.

在此先感谢您的帮助!

解决方案

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

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!

解决方案

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 更改,但未加载视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆