lundi 24 août 2015

Unable to use standalone router.js

I cannot use route.js as standalone witouth ember.js, I dont know what I am really doing wrong, if I use the path "#/posts/123" I get nothing nor with the "#/". What am I missing?, do I have to disable something like HTML5 History?

I get nothing but this in the console: function len(path, nestedCallback)

I have also reviewd some information on their github about a fix on an update that says we must start the instance like this var router = new Router"default"; instead of this var router = new Router(); Also I have included the proper dependent libraries such as rsvp-latest, and so on. To clarify I am not using any other framework nor library but the code example, also there is a html, and body tags that I did not include here. Regards.

<script src="js/plugin/routerjs/rsvp-latest.js"></script>
<script src="js/plugin/routerjs/route-recognizer.js"></script>
<script src="js/plugin/routerjs/router.min.js"></script>



<script type="text/javascript">


    var router = new Router["default"]();

    router.map(function(match) {
        match("#/posts").to("posts", function(match) {
            console.log(match);
            match("/").to("postIndex");
            match("/:id").to("showPost");
        });
    });



    var myHandlers = {}

    myHandlers.posts = {
        model: function() {
            console.log("in posts model");
            return $.getJSON("/posts").then(function(json) {
                return App.Post.loadPosts(json.posts);
            });
        },

        // no serialize needed because there are no
        // dynamic segments

        setup: function(posts) {
            console.log("in posts setup");
            var postsView = new App.PostsView(posts);
            $("#master").append(postsView.el);
        }
    };

    myHandlers.postIndex = {
        setup: function() {

            console.log("posts index setup");

            $("#detail").hide();
        }
    };

    myHandlers.showPost = {
        model: function(params) {

            console.log("show post model");

            return $.getJSON("/posts/" + params.id, function(json) {
                return new App.Post(json.post);
            });
        }
    };



    router.getHandler = function(name) {
        return myHandlers[name];
    };


</script>




Aucun commentaire:

Enregistrer un commentaire