2017-03-27 24 views
0

後,我有2頁:/teamedit/:1/teams和團隊編輯頁面,這裏的路線:ngRoute保持回落至。否則航線使用後退按鈕

app.config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) { 
    var viewBase = '/views/'; 

    $routeProvider 
     .when('/teams', { 
      controller: 'teamsController', 
      templateUrl: viewBase + 'teams/teams.html', 
      controllerAs: 'vm' 
     }) 
     .when('/teamedit/:id', { 
      controller: 'teamEditController', 
      templateUrl: viewBase + 'teams/teamEdit.html', 
      controllerAs: 'vm' 
     }) 
     .otherwise({ redirectTo: '/agents' }); 

    $locationProvider.html5Mode(true); 
}]); 

這裏的步驟是什麼原因我的問題:

  1. /teams頁面點擊按鈕什麼打開/teamedit/1頁面。對於那個在控制器中使用$location.path(url + team);
  2. /teamedit/1加載和我點擊瀏覽器的後退按鈕

現在回到/teams頁我再次單擊該按鈕,我應該把我送到/teamedit/1頁面,但它的作用是BAGE爲第二(控制器代碼加載並執行一切),然後重定向到.otherwise中設置的頁面。

沒有理由回落到otherwise,我該如何解決這個問題?

編輯:添加代碼。 按鈕打開什麼/ teamedit頁:

<button class="btn btn-primary" ng-click="vm.edit('/teamedit/', team.teamId)"> <i class="glyphicon glyphicon-edit"></i> Edit</button> 

teamsController:

(function() { 
    'use strict'; 

    angular 
     .module('actionSyncAdminApp') 
     .controller('teamsController', teamsController); 

    teamsController.$inject = ['$scope', '$location', 'teamsService', 'broadcaster', 'ngProgressFactory']; 

    function teamsController($scope, $location, teamsService, broadcaster, ngProgressFactory) { 
     $scope.title = 'teamsController'; 

     var vm = this; 

     vm.progressbar = ngProgressFactory.createInstance(); 
     vm.progressbar.setParent(document.getElementById('sub-page')); 

     vm.teams = []; 

     vm.new = function (url) { 
      $location.path(url); 
     }; 
     vm.edit = function (url, team) { 
      console.log(url + team); 
      $location.path(url + team); 
     }; 

     activate(); 

     function activate() { 
      vm.progressbar.start(); 
      teamsService.getTeams().then(function (teams) { 
       vm.progressbar.complete(); 
       vm.teams = teams; 
      }); 
     } 
    } 
})(); 
+0

這可能是由您的控制器中的東西造成的。請向我們展示代碼 –

+0

'$ location.path(url + team)'請確保'url'變量在字符串的末尾必須有'/',否則您的URL將變爲'/ teamedit1',否則可能會重定向到' ' –

+0

@AJFunk,我在原文中添加了額外的代碼。 @MaheshSinghChouhan,是的,我有'/'結尾的URL。從原始帖子中檢查代碼。 – hs2d

回答

0

我發現這個問題。這只是我的一個愚蠢的錯誤。我有一個button<a href ></a>這裏面:

<a href tabindex="0" class="accordion-toggle" ng-click="toggleOpen()" uib-accordion-transclude="heading"> 
    <span uib-accordion-header ng-class="{'text-muted': isDisabled}"> 
     <button type="button" class="btn btn-primary" ng-click="vm.edit('/teamedit/', team.teamId)"> <i class="glyphicon glyphicon-edit"></i> Edit</button> 
    </span> 
</a> 

怪你這不僅打破了按鈕我用過之後後退按鈕,而不是頁面加載後的第一次。無論如何,所有的好現在:)