Skip to content

Instantly share code, notes, and snippets.

@ericf
Created December 19, 2012 17:02
Show Gist options
  • Select an option

  • Save ericf/4338310 to your computer and use it in GitHub Desktop.

Select an option

Save ericf/4338310 to your computer and use it in GitHub Desktop.
var app = new Y.App();
app.notify = function (req, res, next) {
if (!this._route_evt) {
this._route_evt = this.publish('route', {
defaultFn: function () {
next();
}
});
}
this.fire('route', {
req: req,
res: res
});
};
app.route('/', 'notify', function (req, res, next) {
var view = new Y.View();
view.get('container').setText('HOME!');
this.showView(view);
});
app.route('/about', 'notify', function (req, res, next) {
var view = new Y.View();
view.get('container').setText('About!');
this.showView(view);
});
app.on('navigate', function (e) {
Y.log('navigating!');
});
app.on('route', function (e) {
Y.log('routing!');
if (e.req.url === '/about') {
// Don't let the user go to "/about", for some reason.
e.preventDefault();
}
});
app.render().navigate('/');
// => "navigating!"
// => "routing!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment