확실히 가능하지만 Backbone의 기본 동작 범위에 포함되지 않습니다. 모든 하위 도메인이 동일한 라우터 코드를 사용한다고 가정하면, 당신은 다음과 같을 수있는 솔루션을 해킹 할 수 :
var Router = Backbone.Router.extend({
routes: {
'*variables': 'buildRoute'
},
subdomain: function() {
// This is probably not the prettiest/best way to get the subdomain
return window.location.hostname.split('.')[0];
},
buildRoute: function(variables) {
// `variables` are all your hash variables
// e.g., in the URL http://variable1.domain.com/#variable3=apples&variable4=oranges
// `variables` here would be the string 'variable3=apples&variable4=oranges'
// so you would have to parse that string into a JSON representation, but that's trivial
// Once you have the JSON, you can do something like:
myView.render(this.subdomain(), variablesJSON);
// Your view's `render` function then has the subdomain and all the variables from the URL,
// so it can use them appropriately.
}
});
이 접근 방식의 한 가지 중요한주의가
: 그것은 자신을 URL로 이동 사용자를 위해 잘 작동하지만 신속 것이다 귀하의 응용 프로그램이 Router
에 navigate
전화를해야 할 때 불안해집니다. 백본은 URL의 해시 부분으로 이동하므로 하위 도메인은 포함되지 않습니다. 다른 작업을 수행하기 전에 window.location
을 설정하는 사용자 지정 탐색 기능을 사용해야 할 것입니다.
물론 이것은 아마도 뭔가가 아닙니다. 백본은 적합합니다. Ember 나 다른 어떤 기능이이 기능을 가지고 있는지 확신 할 수 없지만 의심 스럽습니다. 하위 도메인은 사이트의 고유 한 영역을 의미하므로 올바르게 사용하지 못할 수 있습니다.