두 개의 하위 경로가있는 "게임"이라는 Ember 2 경로가 있습니다. 하나는 "체스"이고 다른 하나는 "체커"입니다. 기본 "게임"경로와 연결된 템플릿을 사용하여 하위 경로가 활성 상태인지 여부에 따라 클래스 이름을 변경합니다.Ember 2 : 서브 루트에 따라 라우터 모델에서 클래스를 적용하는 방법
그래서 내 games.hbs
내가 내 길에 모델을 설정하여이 일을하려고이
<div id="games-page">
<h1 class="{{if model='chess-active' 'color-blue' 'not-color-blue}}">Games</h1>
<section class="game-list">
{{#link-to 'games.chess'}}
Chess
{{/link-to}}
{{#link-to 'games.checkers'}}
Checkers
{{/link-to}}
</section>
{{outlet}}
</div>
같이 보일 것입니다,하지만 난에 현재 하위 경로를 찾을 방법을 알아내는 데 문제가 그에 따라 업데이트하십시오. 내 games.js
경로에서 실패한 접근 방식이 여기에 있습니다.
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return Ember.computed('currentRouteName',function(){
if(this.get('currentRouteName') === 'games.chess'){
return 'chess-active';
}
return 'checkers-active';
})
}
});
하위 루트에 따라 기본 경로 템플릿을 업데이트하는 올바른 방법은 무엇입니까?
하지만 왜? XY 문제처럼 들립니다. – Lux