Monece Solis
Monece Solis

Reputation: 703

How to change url without changing page in backbone

I have a modal that has route of its own and I have an event listener that changes it's route after closing

    'closeTask' : function ( e ) {
        e.preventDefault();
        Backbone.history.navigate( '#groups/' + this.model.get( 'LicenseId' ) + '/tasks' );
    },

but when I use this, there are times when closing the modal it reloads the page.

I also tried using

    'closeTask' : function ( e ) {
        e.preventDefault();
        App.navigate( '#groups/' + this.model.get( 'LicenseId' ) + '/tasks', { trigger:false } );
    },

but also gives me the same result. What should I use so that I can change my route without reloading the page?

Upvotes: 1

Views: 1797

Answers (2)

Monece Solis
Monece Solis

Reputation: 703

Somehow, using replace : true solved my problem.

Backbone.history.navigate('#groups/' + this.model.get( 'LicenseId' ) + '/tasks', { replace : true } );

read there documentation and this actually makes a lot of sense

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

Upvotes: 2

Andrew Hubbs
Andrew Hubbs

Reputation: 9436

This should modify the URL without triggering routing.

Backbone.history.navigate('#groups/' + this.model.get( 'LicenseId' ) + '/tasks', false);

Add false as the second argument to Backbone.history.navigate.

http://backbonejs.org/#Router-navigate

Upvotes: 2

Related Questions