richsoni
richsoni

Reputation: 4278

How to have a link that does not overwrite the URL

I have a link that I typically would have href="#". I would like the url to stay the same when it is clicked, but it seems like backbone copies and pastes the link to the URL no matter what it is. I even put <a href="javascript:alert('true')>Link</a> and the browsers URL was "localhost:5000/javascript:alert('true').

How can I get backbone to refrain from copy and pasting the link to the broswers URL

Upvotes: 1

Views: 293

Answers (1)

machineghost
machineghost

Reputation: 35760

This is one of those "it's a feature not a bug" type of things. Backbone does that on purpose, for (at least) two reasons:

  1. it gives a URL that users can copy/paste, email to each other, etc. and still take them to the correct place in your site; without such URL manipulation that's impossible
  2. it allows for browser-based back/forward functionality (in browsers that don't yet support the history API)

There's probably other reasons too, but that's all I can think of at the moment. The point is, this is what the Backbone router is supposed to do. Using it, and then wondering how to make it not manipulate the URL is somewhat akin to using an <span> on the page and asking how to get let the user edit its text.

If you don't want that functionality, don't use the Router at all; just have your views invoke each other.

Upvotes: 1

Related Questions