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);
}]);
這裏的步驟是什麼原因我的問題:
- 在
/teams
頁面點擊按鈕什麼打開/teamedit/1
頁面。對於那個在控制器中使用$location.path(url + team);
。 /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;
});
}
}
})();
這可能是由您的控制器中的東西造成的。請向我們展示代碼 –
'$ location.path(url + team)'請確保'url'變量在字符串的末尾必須有'/',否則您的URL將變爲'/ teamedit1',否則可能會重定向到' ' –
@AJFunk,我在原文中添加了額外的代碼。 @MaheshSinghChouhan,是的,我有'/'結尾的URL。從原始帖子中檢查代碼。 – hs2d