角度1.5と角度uiルータでは、自分の州の戻るボタンの動作を変更して、州/地域の名前を認識するようにしたいのですが、url/restaurant/1?param1 = & param2 =ページを更新せずに動的に変化する値。私はバインディングとURLがプロパティの変更時に変更されていないが、私が戻るボタンを押すと、名前で$ rootScopeに保存された状態ではなく、以前のparams状態になる。私はこれを何時間もデバッグしていますが、現在のソリューションは時にはうまくいきます。なぜなら、urlの同期が常に呼び出されるわけではないため、URLが更新されても状態は更新されないからです。私は正しく戻るボタンがヒットしたときを正しく認識していますが、状態をリフレッシュしていません。今、私はlocation.assignを使用しなければなりませんが、それはいくつかの時間だけ動作します。とにかく、角度uiルータのdeferInterceptを再同期する必要はありますか?
function bind(propGetters,
getUrl) {
let unwatch = this._$rootScope.$watchGroup(propGetters,() => {
let trimmedUrl = getUrl();
let remove = this._$rootScope.$on('$locationChangeSuccess',() => {
this._$rootScope.disableBackButton = false;
remove();
});
this._$rootScope.disableBackButton = true;
if (!this._$rootScope._hitBackButton) {
this._$rootScope.shouldSync = false;
this._$location.url(trimmedUrl);
}
});
return {
unbind(): void {
unwatch();
}
};
module.run(
($urlRouter, $rootScope) => {
$rootScope.shouldSync = true;
$rootScope.$on('$locationChangeSuccess', e => {
if ($rootScope.shouldSync) {
$urlRouter.sync();
} else if (!$rootScope._hitBackButton) {
e.preventDefault();
}
$rootScope.shouldSync = true;
});
$rootScope.$on("$stateChangeSuccess", (event, toState, toParams, fromState, fromParams) => {
if ($rootScope.previousState) {
if ($rootScope.previousState.name !== fromState.name && !$rootScope.disableBackButton) {
$rootScope.previousState = lodash.merge(fromState, { params: fromParams });
console.log($rootScope.previousState.name, 'previousState');
}
} else {
this._$rootScope.previousState = lodash.merge(fromState, { params: fromParams });
}
});
$rootScope.$on('$locationChangeSuccess', (evt, newUrl, oldUrl) => {
$rootScope.actualPrevious = oldUrl;
if ($rootScope._hitBackButton) {
this._urlProvider.sync();
$rootScope._hitBackButton = false;
}
});
$rootScope.$on('$locationChangeStart', (evt, newUrl, oldUrl) => {
if ($rootScope.actualPrevious === newUrl && $rootScope.previousState && !$rootScope.disableBackButton && !$rootScope._hitBackButton) {
$rootScope.shouldSync = true;
event.preventDefault();
console.log('hit back', $rootScope.previousState.name);
$rootScope._hitBackButton = true;
window.location.assign(this._urlService.getFullPath(this._$state.href($rootScope.previousState.name, $rootScope.previousState.params)))
// this._$state.go($rootScope.previousState.name, $rootScope.previousState.params, { reload: true }); - this doesn't seem to always work because of watch collisions?
}
});
$urlRouter.listen();
});
:バックボタンはdeferInterceptとプラスマイナスreloadOnSearch上記の私の解決策で正常に動作する必要があります)=> { $ urlRouterProvider.deferIntercept(); }); on config – evanjmg
*私はお勧めします:あなたの時間をかけてプランナーを作成してください。より多くの視聴者を獲得し、助けを得る機会を増やすだけでなく、自分で解決策を見つけるのにも役立ちます* –