Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backbone.js Router doesn't fire on page init

i have a quite simple backbone router and everything works fine so far. Except when i reload/direct enter the url i.e. http://mydomain.com/#list/50fadc41125b0 I've tried nearly everything now without any positiv results at all.

myRouter = Backbone.Router.extend({
    routes: {
        "list/:id": "getList",      
        "*actions": "defaultRoute" // not needed right now
    },
    getList: function (id) {
        console.log ("test");
    }
});

i tried it this way as well without any difference

// init router
router = new myRouter;
router.on('route:getList', function (id) {
    [...]
});

i have no i idea how to make this work! hopefully someone has an answer for me!

EDIT:

i also start the history

Backbone.history.start();
like image 687
Horst Avatar asked Oct 22 '22 19:10

Horst


1 Answers

due a mistake i was initializing my router asynchronous in a fetch success statement so Backbone.history.start() had nothing to initialize.

thx to the user Lukas for reminding me to create the router before.

like image 70
Horst Avatar answered Oct 24 '22 10:10

Horst