我正在使用Angular與ui-router。我試圖重構一些代碼,看起來像這樣:
window.location.hash = "order/" + vm.selectedRow.ID;
這樣:
$state.go("^.order", {orderId: vm.selectedRow.ID})
更改爲使用$ state.go手柄導航到該路由就好了,但是,到達那裏之前網址已更新。在關聯控制器的構造函數中,我從當前url的末尾獲取orderId並在查詢中使用它。我正在使用此代碼:
var strings = window.location.href.split('/');
return strings[strings.length - 1];
獲得密鑰。
我應該: 1,繼續設置,而不是使用$ state.go, 2.重構使用$位置,因爲它讓我得到掛起的URL window.location.hash, 3.通行證的ID價值到新的路線使用的控制器?
4.使用$ stateParams服務獲取orderId。 –