Created
June 26, 2012 09:18
-
-
Save olivernn/2994611 to your computer and use it in GitHub Desktop.
davis with hash routing
This file contains 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
Davis.extend(Davis.hashRouting({ forceHashRouting: true })) | |
app = Davis(function () { | |
this.settings.handleRouteNotFound = true | |
this.get('#/foo', function () { | |
console.log('foo') | |
}) | |
this.get('#/bar', function () { | |
console.log('bar') | |
}) | |
}) |
This file contains 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">Foo</a> | |
<a href="#/bar">Bar</a> |
Without the hashRouting plugin it will be using pushState, it just so happens that the url you are using also includes a hash. This will work fine in browsers that support the history api, but will fail in browsers that do not.
Personally I think the best approach with Davis is to only use the pushState and have the server also be able to respond to the urls, sometimes this isn't possible though and in those cases you could use hashRouting.
Then i will use it with hashRouting.
This is my code:
<script type="text/javascript"> Davis.extend(Davis.hashRouting({ forceHashRouting: true })) var app = Davis(function () { this.settings.handleRouteNotFound = true this.use(Davis.title); this.configure(function () { this.generateRequestOnPageLoad = true }); this.get('#/welcome/:name', function (req) { console.log("Hello " + req.params['name']); this.setTitle(req.params['name']); }); }); app.start(); </script>
and now url is: http://localhost/davisjs/##/welcome/oliver with 2 #, what to to with that ?
And second question, there is no ! in url, this is not wrong or ?
This is related to the following issue - olivernn/davis.js#44
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this, but in this case, i don't need hashRouting plugin at all ? It works without that plugin, but is that good way or you can suggest me something else ?