Created
June 26, 2012 08:40
-
-
Save olivernn/2994436 to your computer and use it in GitHub Desktop.
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
var app = Davis(function () { | |
this.configure(function () { | |
this.linkSelector = 'nav a' | |
this.formSelector = 'nav form' | |
}) | |
this.get('/', function (req) { | |
showHomePage() | |
}) | |
this.get('/pay-bill', function (req) { | |
showPayBillPage() | |
}) | |
this.get('/send-money', function (req) { | |
showSendMoneyPage() | |
}) | |
this.get('/contact-us', function (req) { | |
showContactPage() | |
}) | |
this.get('/about-us', function (req) { | |
showAboutPage() | |
}) | |
this.get('/blog', function (req) { | |
showBlog() | |
}) | |
this.post('/search', function (req) { | |
loadSearchResults(req.params['query']) | |
}) | |
}) |
I will try and let you know.
Hi Oliver, don't you think I should do a POST so that the server knows how to respond?
Which route do you think should be a POST? The search could either be a POST or a GET, it really depends on your app to be honest. I think the navigation links should definitly be GET requests as they are links, but again this is depends on how your app works.
As long as the routes you define in Davis match how the server responds then you should be fine, so if without Davis those navigation links make get requests then they should be get requests in davis too.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use relative paths for your links and then for each one that you want to handle with Davis set up a route. The route needs to match on both method and path, so for links that is a get and the path matches the href.
Inside these routes you would do whatever you need when someone clicks on that link. For your use case that might be to render the correct markup in the right place in the page, this is what the show functions might be doing, this part is entirely app specific though.
You also have a post in your navigation and if you wanted to handle this with Davis I have included a matching route. This will pull out the search query and call a function that loads the search results, again this part is entirely app specific.
Assuming that you only want Davis to act on the links and forms inside the nav element I have set the selector that Davis uses for binding to links and clicks to the nav element.