0

일부 전자 메일 클라이언트는 분명히 URL의 해시를 % 23으로 인코딩합니다 (예 : #/path # sectionId는 #/경로 % 23sectionId 또는 % 23/경로 % 23sectionId).

URL에 액세스 할 때 각도에 따라 $ routeProvider를 적절히 사용하고 기본 페이지로 리디렉션합니다. (나는 생각한다)

$ routeProvider.when가 그에 따라 리디렉션되기 전에 어떻게 URL을 디코딩 할 수 있습니까? 이 문제에 대해 알고 계신가요? 페이지의 섹션으로 스크롤 할 때 해시를 사용하지 않는 것이 가장 이상적입니다.

감사합니다.

답변

0

내가 지금까지 발견 한 작업 : 주 컨트롤러에 $ 위치 종속성을 추가하면 $ location.hash가 ''를 반환하고 $ location.path가 '/ path # sectionId'를 반환합니다. 이를 바탕으로

, 우리는 컨트롤러의 상단에 다음과 같이 뭔가를 추가 할 수 있습니다

// when has in url is encoded to %23, location.hash does not recognize it, and it gets cleared from the path in $RouteProvider 
    var holdHash = $location.path(); 
    holdHash = holdHash.split('#'); 
    if (holdHash.length > 1) { // if it has an item after the hash in the array 
     $location.hash(holdHash.pop()); //take that item and use it as a hash 
    } 

하지만 당신은 $의 location.search

의 값을 잃거나 당신이 할 수 있습니다 :

$location.url(decodeURIComponent($location.url())) 

검색을 유지하지만 '?'대신 사용할 수 있습니다. '% 3F'와 비교하여 $ location.search가 아닌 $ location.ash에 반환합니다.

그들은 해키 솔루션 어떻게 든 조금, 그리고 완전히 ****

***** 편집이 솔루션 (은 $ location.search 문제 참조)

으로 작동하지 않습니다 내 문제에 대한 최종 해결책은 ID를 저장 한 서비스를 업데이트하고 메인 컨트롤러에서 해시 탐지를 먼저 트리거합니다.

/** 
    * tries to get hash from $location 
    * if unavailable tries to look for encoded hash 
    * if unavailable returns null 
    * @return {string or null} [a string with the id of the section or null] 
    */ 
    function getHashID() { 
     var fromLoc = $location.hash(), 
     fromEncodedUrl, 
     inPath; 

     if (fromLoc.length) { 
      return fromLoc; 
     } 

     // iphone Chrome encodes the pound sign on redirect 
     fromEncodedUrl = $location.url(); 
     fromEncodedUrl = fromEncodedUrl.split('%23'); 

     if (fromEncodedUrl.length > 1) { 
      return fromEncodedUrl.pop(); 
     } 

     inPath = $location.path(); 
     inPath = inPath.split('#'); 

     if (inPath.length > 1) { 
      return inPath.pop(); 
     } 

     return null; 
    } 

내가 나중에 서비스 객체, 또는 새로운 값을 얻기에 저장된 값에 애니메이션을 트리거하고, 애니메이션 후 : 또한이 염두에 저장할 수있는 모든 변화를 유지하기 위해 탐지를 가지고 업데이트 서비스에서 가치를 지 웁니다.