Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the page url

Tags:

backbone.js

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?

like image 892
Nick Vanderbilt Avatar asked Aug 16 '11 05:08

Nick Vanderbilt


People also ask

Can you change your URL name?

There are really only two ways you can go about changing your domain name — you can change your domain and all associated links at once or you can make the change one section of your site at a time. Both ways risk affecting your SEO, so choose the one better for you.


2 Answers

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

router.navigate('cart');
like image 186
Dan Brooke Avatar answered Sep 16 '22 19:09

Dan Brooke


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
like image 42
stefan Avatar answered Sep 17 '22 19:09

stefan