URL87
URL87

Reputation: 11022

backbone.js router - simple example doesn't work

Having -

default.html

<html>
<head>
</head>
<body>
    <script src="jquery-2.1.0.min.js"></script>
    <script src="json2.min.js"></script>
    <script src="underscore.js"></script>
    <script src="backbone.js"></script>
        <script>
            Router = Backbone.Router.extend({
                routers: {
                    "*action" : "func"
                },
                func: function (action) {
                    console.log(action);

                }
            });

            new Router();
            Backbone.history.start(); 
        </script>

</body>
</html>

According to the routers format it has to print to the console the suffix after the # .

For example for the path default.html#hello it has to print hello on the console , but in actually nothing printed .

What is wrong here ?

Upvotes: 0

Views: 324

Answers (1)

Jonathan Beebe
Jonathan Beebe

Reputation: 5226

Your routes need to be defined in the routes key, not routers:

        var Router = Backbone.Router.extend({
            routes: {
                "*action" : "func"
            },
            func: function (action) {
                console.log(action);

            }
        });

Here is a working jsfiddle: http://jsfiddle.net/somethingkindawierd/WJ5V7/

Upvotes: 3

Related Questions