# davisjs **Repository Path**: mirrors/davisjs ## Basic Information - **Project Name**: davisjs - **Description**: Davis.js 是一个小型的 JavaScript 库,使用 HTML5 的 history.pushState 方法来允许在 JavaScript 应用中实现 Sinatra - **Primary Language**: JavaScript - **License**: Not specified - **Default Branch**: master - **Homepage**: https://www.oschina.net/p/davisjs - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2020-07-17 - **Last Updated**: 2023-09-12 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Davis.js ## Description Davis.js is a small JavaScript library using HTML5 history.pushState that allows simple Sinatra style routing for your JavaScript apps. ## Why Using the history pustState and popstate events allows the links and forms in your app to have hrefs and actions that point to real end points on your server. This allows complex JavaScript apps to degrade gracefully when JavaScript is unavailable and combining this with a template system that can be used both client and server side allows for large amounts of code reuse. Davis.js is heavily inspired by [Sammy.js](https://github.com/quirkey/sammy) (hence the name), it is however intentionally much lighter than Sammy.js because I never use any of the template rendering etc that it includes. All Davis.js does is provide a simple routing layer, nothing more, nothing less. ## Requirements Davis.js requires jQuery 1.4.2+ as well as a modern browser that supports HTML5 history.pushState and the onpopstate event. At the moment that means FireFox 4+, Safari 5+, Chrome, iOS Safari 4+*, Android Browser 2.2+, Opera 11.50+. In all other browsers Davis.js is currently unsupported, all links and forms will have their default behaviour. You can bind to the 'unsupported' event on an app to handle this situation in your code. Fallback to `location.hash` and `onhashchange` is a possibility in the future. *Whilst pushState is supported in iOS it has several, fairly serious bugs. Davis will not fire the unsupported event though as _technically_ iOS does support davis. ## Installation Download davis.min.js and include it on your page after jquery. ## Example A very simple example of a Davis.js app: var app = Davis(function () { this.get('/welcome/:name', function (req) { $('body').append('