그래서 라우터가 발생하는 것을 방지하려면 backbone.js
에있는 라우터를 제거해야합니다. 행운없이 myRouter.off()
과 myRouter.remove()
을 시도했습니다.backbone.js에서 라우터 바인드 해제
대신 무엇을 할 수 있습니까?
그래서 라우터가 발생하는 것을 방지하려면 backbone.js
에있는 라우터를 제거해야합니다. 행운없이 myRouter.off()
과 myRouter.remove()
을 시도했습니다.backbone.js에서 라우터 바인드 해제
대신 무엇을 할 수 있습니까?
내가 알고있는 공식적으로 지원되는 방법은 없습니다. 당신이 어떤 라우터를 사용하지 않으려면, 당신은 불법이지만,이 의견에 소스 코드에 표시 Backbone.history.stop();
사용할 수 있습니다 : 일부 통과 조건을 코딩 그렇지 않으면
// Disable Backbone.history, perhaps temporarily. Not useful in a real app,
// but possibly useful for unit testing Routers.
을, 당신이 한 것 당신의 라우터의 상태가 "사용 안 함"또는 이와 비슷한 경우 라우터의 라우팅 처리기. 또는 문서화되지 않은 Backbone.history.handlers (.route - 정규 표현식과 .callback을 포함하는 내부 배열)을 반복하고이 특정 라우터와 관련된 라우트를 제거하십시오.
분명히, 문서화되지 않았지만이 모든 것은 Backbone의 향후 릴리스에서 변경 될 수 있습니다.
당신이 당신의 라우터의 인스턴스를 제어 할 수있는 경우, 다음을 수행 할 수 있습니다
var myRouter = new MyRouter({ routes: function(){
return;
}});
당신이 (가 아닌 API 방법을 사용 해킹 기반 솔루션을 사용하여 새로운 버전으로 작동하지 않을 수 있습니다
var router = new(Backbone.Router.extend({
routes: {
"authentication": "authentication",
"contacts": "contacts",
"*notFound": "notFound"
},
/**
* @param {string} routeName
*/
disableRoute: function(routeName) {
var index, handler, handlers = Backbone.history.handlers;
delete this.routes[routeName];
for (var i = 0, len = handlers.length; i < len; i++) {
handler = handlers[i];
if (handler.route.toString() === router._routeToRegExp(routeName).toString()) {
handlers.splice(index, 1);
break;
}
}
},
contacts: function() {
alert('route `contacts`');
},
authentication: function() {
alert('route `authentication`');
},
notFound: function() {
alert('route `notFound`');
router.navigate('404');
}
}));
Backbone.history.start({
silent: true
});
$(function() {
$('#remove').on('click', function() {
router.disableRoute('authentication');
router.navigate('404');
});
$('#goto_auth').on('click', function() {
router.navigate('authentication', {
trigger: true
});
});
$('#goto_contacts').on('click', function() {
router.navigate('contacts', {
trigger: true
});
});
});
button {
display: block;
margin: 10px;
}
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.2/backbone-min.js"></script>
</head>
<body>
<button id="goto_auth">goto authentication route</button>
<button id="goto_contacts">goto contacts route</button>
<hr>
<button id="remove">remove authentication route</button>
</body>
</html>
재미) Backbone.js, 나는이 앱이 유용 로그 아웃 후 비활성화 생각, 난을 처리 할 수있는 다른 방법이 있습니다 난 백본을 정말로 좋아할거야. 역사. 정지 – pushplaybang