page-router
Powerfully simple client-side ajax template router built on page.js.
index.js
var router = ;var fs = var routes = url: '/' template: '<h1>{{title}}</h1>' { // get data to be rendered in the template } url: '/post/:id' template: '<h1>{{post.title}}</h1>' { // your route to get data. do some stuff } { // anything you can do with Ractive.js console }
Your index.html
Using browserify
If you use browserify (recommended), you can use fs.readFileSync(template_path).toString()
to load the file into the client-side javascript bundle.
Example:
var fs = var routes = url: '/post/:id' template: fs { console }
Use with gh-pages
Rename index.html to 404.html and then symlink index to 404.
ln -s 404.html index.html
turn off auto-scroll
When you click, the router will automatically scroll to the top (see line 28 of index.js). Use scroll: false
in any route definition to turn this off.
TODO
- handle 404s correctly. make the 404.html trick for gh-pages not be necessary