2016-07-24 3 views
2

:폴리머, 사슬로 매인 앱 경로 요소의 변화 경로 나는 다음과 같은 구조의 프로젝트에 <a href="https://github.com/PolymerElements/app-route" rel="nofollow">https://github.com/PolymerElements/app-route</a>에서 앱 경로 요소를 사용하고

다음 코드가 포함 된 my-app 요소 :

<app-location route="{{route}}"></app-location> 
<app-route 
    route="{{route}}" 
    pattern="/:page" 
    data="{{routeData}}" 
    tail="{{subroute}}"> 
</app-route> 

<iron-pages selected="[[page]]" attr-for-selected="name"> 
    <store-main-page 
    name="loja" 
    route="{{subroute}}" 
    categories="[[categories]]"> 
    </store-main-page> 
    ... 
</iron-pages> 
... 

store-main-page 요소 A : 환영 페이지를 표시 할 수 있도록

<app-route 
    route="{{route}}" 
    pattern="/:page" 
    data="{{routeData}}" 
    tail="{{subroute}}"> 
</app-route> 

<iron-pages selected="[[page]]" attr-for-selected="name"> 
    <category-page 
    name="categoria" 
    route="{{subroute}}" 
    selected-category="{{selectedCategory}}" 
    cart="{{cart}}"> 
    </category-page> 
    ... 
</iron-pages> 
... 

에 액세스 /되는 경로 /loja/categoria에 액세스하면 my-appcategory-page을 호출 할 store-main-page을 호출합니다.

내 문제는 store-main-page을 표시하기 전에 사용자를 인증하고 사용자가 인증되지 않은 경우 사용자를 환영 페이지로 다시 지정하여 /에 리디렉션합니다. app-route을 사용하여이를 수행 할 수 있습니까?

내가 app-route

this.set('route.path', 'path'); 

를 호출하는 것입니다 사용하여 페이지를 변경하는 것으로하지만 내 상황에, 체인 경로에서 작동하지 않는 유일한 방법은,이없는 것입니다 /loja/ 경로로 리디렉션에 발생합니다 내가 원하는.

어떻게 상위 요소의 경로를 변경할 수 있습니까? 그게 가능하니?

답변

3

방금 ​​app-locationiron-locationapp-route 사이의 인터페이스임을 알게되었습니다.

그래서 내 자식 요소에 iron-location을 추가하고 path 속성을 변경하는 문제를 해결했습니다.

정확한 코드이었다

<iron-location id="ironLocation"></iron-location> 
... 
</template> 

<script> 
... 
    attached: function() {      
    if (!userAuth()) {    
     this.$.ironLocation.set('path', '/');    
    } else { 
     ... 
    }          
    } 
... 

이 이상적인 솔루션입니다 경우 나도 몰라,하지만 작동합니다.