を使用して望むように歴史を修正されるまで待機しますRishabhの答え、sergeyのlocation.skipReloadをthis Angular Issueから使用すると、ルート変更に関するダイアログを作成し、URL変更を無期限に延期し(実際にはルート変更をキャンセルする)、URLバーを '/'別の再読み込みを行わずに:
//Override normal $location with this version that allows location.skipReload().path(...)
// Be aware that url bar can now get out of sync with what's being displayed, so take care when using skipReload to avoid this.
// From https://github.com/angular/angular.js/issues/1699#issuecomment-22511464
app.factory('location', [
'$location',
'$route',
'$rootScope',
function ($location, $route, $rootScope) {
$location.skipReload = function() {
var lastRoute = $route.current;
var un = $rootScope.$on('$locationChangeSuccess', function() {
$route.current = lastRoute;
un();
});
return $location;
};
return $location;
}
]);
app
.config(['$routeProvider', function ($routeProvider) {
$routeProvider
.when('/home', {
controller: 'HomeCtrl',
templateUrl: 'Home/HomeView.html'
})
.when('/profile/:userId/changepwd', {
template: ' ',
controller: '',
resolve: {
data1: function($dialog, location, $q){
$dialog.messageBox(title, msg, btns)
.open()
.then(function(result){
//fires on modal close: rewrite url bar back to '/home'
location.skipReload().path('/home');
//Could also rewrite browser history here using location?
});
return $q.defer().promise; //Never resolves, so template ' ' and empty controller never actually get used.
}
}
})
.otherwise({
redirectTo: '/'
});
これは解決されていない約束が漏れているように感じるし、きれいな解決策があるかもしれないが、これは私の目的のために働いた。
ルートを「キャンセル」するときは、彼が出てきた場所( '$ window.history.back()')に戻るか、ダイアログボックスとやりとりした後にリダイレクトすることを意味しますか( ' $ location.path( '/ new') ')? –