Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set routes in Parse.com? Alternative to Parse.Router

What's the simplest way to integrate a Router? This https://parse.com/questions/how-to-create-website-with-parse suggests to add in Backbone.js next to Parse.

How do I go about doing that in the lightest fashion?

Wondering if the Parse team is planning a Parse.Router class :)

like image 869
Gon Zifroni Avatar asked Aug 04 '12 21:08

Gon Zifroni


2 Answers

The earlier response is outdated. Parse JS SDK now includes a router. Use Parse.Router and Parse.history.

like image 75
Evil Nodoer Avatar answered Sep 20 '22 01:09

Evil Nodoer


My approach so far is to include a script link to backbone.js (which you get from the site) right after underscore.js since it is a backbone.js requirement just as it is a parse.js one, like so

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="js/underscore-1.1.6.js"></script>
<script src="js/backbone.js"></script>
<script src="http://www.parsecdn.com/js/parse-1.0.10.min.js"></script>
<script src="js/myApp.js"></script>

And then creating a Backbone.Router instance like so

$(function() {

  Parse.$ = jQuery;

  // Initialize Parse with your Parse application javascript keys
  Parse.initialize("YOUR_APPLICATION_ID", "YOUR_JAVASCRIPT_KEY");

  // Router
  var Workspace = Backbone.Router.extend({

    routes: {
      "help":                 "help",    // #help
      "search/:query":        "search"  // #search/kiwis
    },

    help: function() {
      // 
      console.log("help");
    },

    search: function(query, page) {
      //
      console.log("search query is "+query);
    }

  });
  this.Router = new Workspace();
  Backbone.history.start();


  // Models ...

  // Views ...
like image 29
Gon Zifroni Avatar answered Sep 21 '22 01:09

Gon Zifroni