You can simply check for the presence of the main view and create / open it if it does not already exist.
I usually create (but do not open) the main types of my application when the application loads, and then some kind of view manager for opening / closing. For small projects, I just bind my views to the views property of my application object, so that they are all in one place, available as view.mainView, views.anotherView, etc.
I also extend Backbone.View in two ways: open and close , which not only adds / removes the view to / from the DOM, but also sets the isOpen flag in the view.
With this, you can check if an already open view is open, and then open it if not, for example:
if (!app.views.mainView.isOpen) {
An additional addition would be to create a method in your application called clearViews that clears any open views, possibly with the exception of the names of the views passed as parameters to clearViews . Therefore, if you have a navigation view that you do not want to delete on some routes, you can simply call app.clearViews('topNav') and all views except views.topNav will be closed.
check this meaning for the whole code: https://gist.github.com/4597606
source share