Spine go to another page

This is probably a very simple question, so I attach the 'click' event to the button when that event is clicked. I want to redirect to a completely new page (for example, not a route).

eg.

events : { "click .button" : 'redirect' }, redirect : { window.location('otherlink'); } 

I could use window.location, but it seems like it is not? Any ideas appreciated?

+7
source share
2 answers

I would just use a simple <a href="otherlink">Link Title</a> . If the link is dynamic, I would rely on the view to display the link and manage its state and href .

If you need to do something before , to allow the user to switch to using the secondary page and event handler without event.preventDefault() or to avoid returning false .

+2
source

The backbone has a "router" (basically this is what I learned as a controller). You can use it for navigation. For example:

 var MyApp = new Backbone.Router(); MyApp.navigate('newPage', {trigger: true}); 

fires an event if you use the specified events.

You can combine the router with the "Backbone" story and create a very simple application on one page.

Edit: Nothing, I just re-read that you didn't want to use the route. My two cents - make a wrapper to make navigation for you. I just had to reorganize a rather large javascript application a few weeks ago, pulling out a hundred or so windows.locations so that it could be tested. Not so much fun. I.e:

 MyApp = { navigate: function (url) { window.location = url; } } 

You can now do unit testing, since you can override MyApp.navigate with something that does nothing when called. You can also add to the business logic if necessary .. or filters .. or anything else .. without having to bother the rest of the application. For example, if the URL is outside the site, open it in a new window, and not just show it on the same page.

+13
source

All Articles