Nick Vanderbilt
Nick Vanderbilt

Reputation: 1777

How to change the page url

I am building a shopping cart using backbone.js . When some one clicks on 'add to cart' I am making an ajax call using jQuery. Backend is rails. In response I get the new json value for the cart. However if I display the cart view then car view comes up , however the url does not change.

To make the url change I after receiving the response from jQuery I need to do something so that router catches the new url and things proceed from there.

How do I navigate to the #cart url?

Upvotes: 14

Views: 16724

Answers (2)

stefan
stefan

Reputation: 427

Most likely your view doesn't have access to the router you can do this:

Backbone.history.navigate('cart', {trigger:true});  // router handles view change


Backbone.history.navigate('cart');                  // only url is updated

Upvotes: 10

Dan Brooke
Dan Brooke

Reputation: 1577

You can update the URL by calling the navigate method on your router, like this:

router.navigate('cart');

Upvotes: 25

Related Questions