Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backbone.history.navigate(url,{trigger:true, replace: true})

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

like image 412
user2508256 Avatar asked Dec 23 '13 08:12

user2508256


Video Answer


1 Answers

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.

like image 187
Aubricus Avatar answered Sep 20 '22 12:09

Aubricus