react-crossroads
Version:
Client side router for web applications built with React and utilizing the Flux architecture. The backing routing engine is CrossroadsJs.
66 lines (52 loc) • 1.73 kB
text/coffeescript
RouterConstants = require '../constants/RouterConstants'
Logger = require '../utils/logger'
pattern = require('crossroads').patternLexer
isAbsoluteUrl = (url) -> typeof url == 'string' and /^https?:\/\//.test url
class RouterActions
constructor: (, ) ->
_dispatch: (action) ->
if .location.isBlocked()
action =
actionType: RouterConstants.LOCATION_ATTEMPT
originalAction: action
.handleRouteAction action
_resolvePath: (to, params) ->
switch
when isAbsoluteUrl to
to
when .route.hasRoute to
.route.pathTo to, params
else
pattern.interpolate to, params
transition: (to, params) ->
path = to, params
Logger.debug.log "RouterActions.transition(#{path})"
actionType: RouterConstants.LOCATION_CHANGE
path: path
fromLocationEvent: false
replace: (to, params) ->
path = to, params
Logger.debug.log "RouterActions.replace(#{path})"
actionType: RouterConstants.LOCATION_REPLACE
path: path
back: ->
Logger.debug.log "RouterActions.back()"
actionType: RouterConstants.LOCATION_GOBACK
block: (id) ->
.handleRouteAction
actionType: RouterConstants.LOCATION_BLOCK
blockId: id
unblock: (id) ->
.handleRouteAction
actionType: RouterConstants.LOCATION_UNBLOCK
blockId: id
updateLocation: (path) ->
Logger.debug.log "RouterActions.updateLocation(#{path})"
actionType: RouterConstants.LOCATION_CHANGE
path: path
fromLocationEvent: true
module.exports = RouterActions