이벤트 변수는 속성을 사용하여 change
함수에 전달됩니다. 모니터링하려는 속성은 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를 기반으로 페이지의 새로운 페이지를로드하거나 페이지의 어딘가에 작은 변경 만 수행 할 수 있습니다.
코드를 게시 할 수 있습니까? –