Skip to content

Instantly share code, notes, and snippets.

@richard-flosi
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richard-flosi/9511230 to your computer and use it in GitHub Desktop.
Save richard-flosi/9511230 to your computer and use it in GitHub Desktop.
Spine with HTML5 History. How to navigate your links without reloading your app and handle the cases when you want to open a link in a new window.
require('lib/setup')
Spine = require('spine')
$ = Spine.$
Spine.Route = require('spine/lib/route')
Stacks = require('controllers/stacks')
class App extends Spine.Controller
constructor: ->
super
stacks = new Stacks(el: $('#app'))
Spine.Route.setup(history: true)
events: {
'click a': 'navigate'
}
navigate: (e) ->
if e.currentTarget.target
# external link
$.noop();
else if e.metaKey
# open link in new window
$.noop();
else
# navigate using push state
e.preventDefault();
Spine.Route.navigate(e.currentTarget.pathname);
module.exports = App
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment