R
R
Roman Makarov2015-12-22 10:09:00
backbone.js
Roman Makarov, 2015-12-22 10:09:00

How to prevent navigation through Backbone.js anchors?

In the address bar, the value changes, in the console the link is displayed correctly, but the transition does not occur
. Here is my attempt:

$(document).on('click', 'a[href^="#"]', function (e) {
            e.preventDefault();
            var link = this.hash.substr(1);
            console.log(link);
            Backbone.history.navigate(link);
        });

here are the routes
routes: {
                '': 'viewData',
                'collections': 'viewCollections',
                'databases': 'databases'
            }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
timfcsm, 2015-12-22
@rmakarov

1. you need to call the navigate method on the router
2. pass trigger: true in the parameters
router.navigate(link, {trigger: true});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question