Created
October 15, 2011 21:46
-
-
Save mxriverlynn/1290199 to your computer and use it in GitHub Desktop.
tips for using backbone routers with pushstate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <a href="#foo">Say "foo"</a><br/> | |
| <a href="#bar">Say "bar"</a><br/> | |
| <div id="output"></div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| MyRouter = Backbone.Router.extend({ | |
| routes: { | |
| "foo": "foo", | |
| "bar": "bar" | |
| }, | |
| foo: function(){ | |
| $("#output").append("foo!<br/>"); | |
| }, | |
| bar: function(){ | |
| $("#output").append("bar!<br/>"); | |
| } | |
| }); | |
| new MyRouter(); | |
| Backbone.history.start(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <a href="/foo">Say "foo"</a><br/> | |
| <a href="/bar">Say "bar"</a><br/> | |
| <div id="output"></div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| MyRouter = Backbone.Router.extend({ | |
| routes: { | |
| "foo": "foo", | |
| "bar": "bar" | |
| }, | |
| foo: function(){ | |
| $("#output").append("foo!<br/>"); | |
| }, | |
| bar: function(){ | |
| $("#output").append("bar!<br/>"); | |
| } | |
| }); | |
| new MyRouter(); | |
| Backbone.history.start({pushState: true}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <a href="/foo" class="foo">Say "foo"</a><br/> | |
| <a href="/bar" class="bar">Say "bar"</a><br/> | |
| <div id="output"></div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| MyView = Backbone.View.extend({ | |
| events: { | |
| "click a.foo": "foo", | |
| "click a.bar": "bar" | |
| }, | |
| foo: function(e){ | |
| e.preventDefault(); | |
| history.navigate("foo"); | |
| $("#output").append("foo"); | |
| }, | |
| bar: function(e){ | |
| e.preventDefault(); | |
| history.navigate("bar"); | |
| $("#output").append("bar"); | |
| } | |
| }); | |
| new MyView({el: $("body")}); | |
| history = new Backbone.History(); | |
| history.start({pushState: true}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment