vendor/assets/javascripts/spine/route.coffee in spine-rails-0.1.1 vs vendor/assets/javascripts/spine/route.coffee in spine-rails-0.1.2
- old
+ new
@@ -16,10 +16,11 @@
@options:
trigger: true
history: false
shim: false
replace: false
+ redirect: false
@add: (path, callback) ->
if (typeof path is 'object' and path not instanceof RegExp)
@add(key, value) for key, value of path
else
@@ -62,14 +63,21 @@
return if @path is path
@path = path
@trigger('navigate', @path)
- @matchRoute(@path, options) if options.trigger
+ route = @matchRoute(@path, options) if options.trigger
return if options.shim
+ if !route
+ if typeof options.redirect is 'function'
+ return options.redirect.apply this, [@path, options]
+ else
+ if options.redirect is true
+ @redirect(@path)
+
if @history and options.replace
history.replaceState({}, document.title, @path)
else if @history
history.pushState({}, document.title, @path)
else
@@ -97,9 +105,12 @@
@matchRoute: (path, options) ->
for route in @routes when route.match(path, options)
@trigger('change', route, path)
return route
+
+ @redirect: (path) ->
+ window.location = path
constructor: (@path, @callback) ->
@names = []
if typeof path is 'string'