N
N
Nikolay Kazakov2014-08-10 10:09:54
JavaScript
Nikolay Kazakov, 2014-08-10 10:09:54

Why does Backbone.Router stop working after using histoty.pushState?

Good afternoon!
The page has a backbone router of the following form (abbreviated version)

Controller = Backbone.Router.extend({
        routes: {
            "sendpm/:dialogWith": "sendpm" 
        },
        sendpm: function(dialogWith) {
            $("#popup-send-pm").simplePopup();
            if (PM != undefined && typeof PM.init == "function")
                PM.init(dialogWith);

            // Загружаем информацию о пользователе
            PM.getUserInfo();
        }
    });
    controller = new Controller(); 
    Backbone.history.start();

A link like site.ru/#sendpm/123 will open a dialog box for sending a private message. When closing the window, to get rid of the hash sign (#) I do the following
history.pushState('', document.title, window.location.pathname);

The page does not reload, the url becomes clean, but trying to call the route again via #sendpm does not work, the route does not work, what could be the reason?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Bobylev, 2014-08-21
@finethanks

Make an empty route and use the backbone's navigate method on that route when the window closes.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question