イベント変数は、プロパティとともに関数に渡されchange
ます: value, path, pathNames, parameterNames, parameters, queryString
. 監視するプロパティは ですpathNames
。
ここに私がまとめたいくつかのスニペットがあります:
var $current_path = window.location.hash;
$.address.change( function(event) {
// get the difference in the two paths
$changed_path = event.path.replace(new RegExp('^'+$current_path,'i'), '');
// make sure we update the current path
$current_path = event.path;
// how deep is the new path?
$level = event.pathNames.length;
// break the changed part into segments, ignoring leading/trailing slashes
$changed_path_array = $changed_path.replace(/^\/|\/$/g, '').split('/');
// let's see what level actually changed from the current path
$changed_level = $level - $changed_path_array.length;
} );
次に、新しい深さをセグメントの配列と組み合わせて使用して、更新が必要なものを正確に特定することにより、残りの関数を整理できます。$current_path に基づいて、新しいページの読み込みを行っているか、ページのどこかで小さな変更を行っている可能性があります。