2014-10-28 3 views
1

쿼리 문자열을 유지하지 않으려면 AngularJS의 경로 변경 전체에서 쿼리 문자열을 지속하는 데 문제가 있습니다. 이 문제를 재현하려는 plunker (아래)를 만들었지 만 this question에 명시된 바와 같이 쿼리 문자열이 일반적으로 경로 변경을 통해 유지되지 않습니다.AngularJS ngRoute를 사용하여 쿼리 문자열을 지속하지 않으려면

http://plnkr.co/edit/SD8QMdSeAfAnVP3ZNHK4?p=preview

var demo = angular.module('demo', ['ngRoute']); 

demo.config(function ($routeProvider) { 

    $routeProvider.when('/page1', { 
    template: 
"<h1>{{ctrl.title}}</h1>" + 
"<ul>" + 
"<li>Page 1</li>" + 
"<li><a href=\"#/page2/Title\">Page 2</a></li>" + 
"</ul>" + 
"<p>{{ctrl.currentUrl}}</p>" + 
"<p>{{ctrl.queryString}}</p>", 
    controller: 'Page1', 
    controllerAs: 'ctrl' 
    }); 

    $routeProvider.when('/page2/:param', { 
    template: 
"<h1>{{ctrl.title}}</h1>" + 
"<ul>" + 
"<li><a href=\"#/page1\">Page 1</a></li>" + 
"<li>Page 2</li>" + 
"</ul>" + 
"<p>{{ctrl.currentUrl}}</p>" + 
"<p>{{ctrl.queryString}}</p>" + 
"<button ng-click=\"ctrl.appendQS()\">Append query string</button>", 
    controller: 'Page2', 
    controllerAs: 'ctrl' 
    }); 

    $routeProvider.otherwise({ redirectTo: '/page1' }); 

}); 

demo.controller('Page1', function Page1($location) { 
    this.title = 'Page 1'; 
    this.currentUrl = $location.url(); 
    this.queryString = $location.search(); 
}); 

demo.controller('Page2', function Page2($routeParams, $location) { 
    this.title = $routeParams.param; 
    this.currentUrl = $location.url(); 
    this.queryString = $location.search(); 
    this.appendQS = function() { 
    $location.search('foo', 'bar'); 
    }; 
}); 

난 그냥 AngularJS와 1.3로 업그레이드하지만 1.2 이전 버전에서 동일한 행동을 발견했다. (12 | 24). 불행히도 문제가있는 소스 코드는 독점적이므로 문제를 일으키는 정확한 코드를 공유 할 수 없습니다.

모든 것을 시도했지만 Angular 소스로 디버그하여 내 쿼리 문자열이 경로 변경 전체에서 지속되는 이유를 확인했습니다. 다른 사람이이 문제를 겪었거나 사용 중지 방법을 알고 있습니까?

업데이트

등 단순히 stripping off the query string 등의 솔루션이 실제로 어떤 쿼리 문자열 매개 변수에 대한 기본 값을 포함 내 링크의 많은 작동되지 않습니다.

답변

0

나는 그 질문의 전제가 틀린 것을 발견했다. 이 상황이 발생한 단일 시나리오가 있었고 수동으로 $location.path을 사용하여 새 URL로 라우팅하려고했습니다. 앵커 클릭이 통과하여 링크로 처리되도록하여이 문제를 해결했습니다.

관련 문제