I generally access my Parse app by going to www.mysite.com
.
However, I want to be able to do something like www.mysite.com/code
or www.mysite.com?page=code
, and for this to show a specific view within the app, without having to click through. In other words, I want to detect that a GET variable is present, and use it to determine which view to show.
Can anyone point me in the right direction?
You can use Backbone's Router. There's an example in the Anypic.org source code you can use.
var AppRouter = Backbone.Router.extend({
routes: {
"pic/:object_id": "getPic",
"*actions": "defaultRoute"
},
getPic: function(object_id) {
App.showLandingPage();
var query = new Parse.Query(Photo);
query.include("user");
query.get(object_id, {
success: function(photo) {
App.landingPageView.showPhoto(photo);
},
error: function(object, error) {
console.error(error);
// The object was not retrieved successfully.
// error is a Parse.Error with an error code and description.
App.landingPageView.showError();
}
});
},
defaultRoute: function(actions) {
App.showHomePage();
}
});
In this example, navigating to https://anypic.org/pic/XXXXX will call getPic and pass along the value of XXXXX to the getPic function.