Sha256: 9347cbaa476564c2d015caf1647b9c95c7d90f791f22a51a8a0c0f0f56ad7238
Contents?: true
Size: 1.41 KB
Versions: 27
Compression:
Stored size: 1.41 KB
Contents
# Wraps a link with the logic necessary to trigger a navigate event on our # router. If a route is not available on any router, fall back to normal link # behavior. Rev.registerComponent 'RouterLink', render: -> <a onClick={ @onClick } {...@props}>{ @props.children }</a> # Check for route match on any router and then trigger navigation if it is # supported. If it is not, we'll have normal link click behavior. onClick: (e)-> # Any router matches if @hasMatch() e.preventDefault() # Save the current URL on the history stack, don't trigger callbacks # This means our back button can take us back to this page after we swap Backbone.history.navigate(Backbone.history.fragment, trigger: false) # Finally actually trigger the navigation & component swap Backbone.history.navigate @props.href, trigger: true true # Backbone routers don't behave well with a slash at the begining of a route # and also don't handle matching well when a URL starts with a slash. But we # want absolute paths in URLs so the fallback behavior will be right. Also, the # call to `Backbone.history.navigate` wants the slash? Trim it for matching # only. bbNormalHref: -> if @props.href[0] == '/' then @props.href[1..] else @props.href end hasMatch: -> if @props.href? _(Backbone.history.handlers).any (handler)=> handler.route.test(@bbNormalHref()) else false
Version data entries
27 entries across 27 versions & 1 rubygems