Answer the question
In order to leave comments, you need to log in
Why is the view not rendered when navigating to the url via router.navigate?
And so, there is a router on 2url
var Router = Backbone.Router.extend({
routes: {
'' : 'homepage',
'users' : 'user'
},
users : function(){
var userView = new UsersView();
userView.render();
},
homepage: function(){
var homepageView = new HomepageView();
homepageView.render();
}
})
var HomepageView = Backbone.View.extend({
el: 'body',
events: {
'click #button': 'show'
},
show: function(){
router.navigate('users', {trigger: true})
},
template: _.template($("#homepageTemplate").html()),
render: function(){
this.$el.html(this.template())
return this;
}
})
<script type="text/template" id="homepageTemplate">
<h1>Welcome</h1>
<button id="button">Button</button>
</script>
Answer the question
In order to leave comments, you need to log in
Nothing is rendered because you are following a link inside the page without contacting the server (see what an anchor is )
router.navigate('users', {trigger: true,replace:true})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question