Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
140
rated 0 times [  145] [ 5]  / answers: 1 / hits: 23749  / 11 Years ago, mon, december 23, 2013, 12:00:00

I used this method to navigate to url, trigger an event and not push url to browser history. But Backbone.history.navigate(url,{trigger:true, replace: true}) replace previous url from history.
Example: Browser hystory



Before



localhost:port/url



Backbone.history.navigate(url + '/list',{ trigger:true, replace: true })



Expected: trigger event on route url + '/list' and Browser history localhost:port/url
Actually: triggering event but Browser history localhost:port/#url/list.
Previous url is replaced


More From » url

 Answers
11

Here's what I think you're asking, please correct me if I'm wrong:



How do I trigger a route in Backbone without updating the URL?



Quick Answer:



You can't. The replace option will also not help you there. Here's a snippet from the docs:




To update the URL without creating an entry in the browser's history, set the replace option to true.




As you can see replace does not affect the update to the URL.



Subsequent Answer:



If you don't want the URL to update, this makes me think that showing a list in your application is not a major update to your application state. If that's true, then you shouldn't, in my experience, use the Backbone.history object to manage it.



If you called this functionality either directly (e.g., through a function) or indirectly (e.g., by dispatching an event) then your app would update and your URL wouldn't.



I like Derick Baily's Post on how to set up your router structure. It's a bit lengthy but worth a read.



Also, check out David Sulc's repo for A Gentle Introduction to Marionette. I know it's using Marionette.AppRouter objects, but the principals are still sound. Check out this file for an example.



As a side note, if the # is the problem; check out this SO answer. Be wary, however, the hashChange option is mostly for x-browser compatibility according to the docs.


[#73584] Saturday, December 21, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kristinsonjab

Total Points: 364
Total Questions: 98
Total Answers: 98

Location: Christmas Island
Member since Mon, Oct 19, 2020
4 Years ago
kristinsonjab questions
Fri, Mar 4, 22, 00:00, 2 Years ago
Fri, Jan 22, 21, 00:00, 3 Years ago
Fri, Aug 14, 20, 00:00, 4 Years ago
;