UNPKG

react-crossroads

Version:

Client side router for web applications built with React and utilizing the Flux architecture. The backing routing engine is CrossroadsJs.

55 lines (40 loc) 1.55 kB
var React, Route, RouteDefinition, TYPE, factory, merge, _atLeastOneUnlessDefault, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; React = require('react'); RouteDefinition = require('./RouteDefinition'); merge = require('react/lib/merge'); TYPE = 'Route'; _atLeastOneUnlessDefault = function(props, propName) { if (!((props.name != null) || (props.path != null))) { return new Error('Must provide either a name, a path or both'); } return React.PropTypes.string.apply(null, arguments); }; Route = (function(_super) { __extends(Route, _super); Route.prototype.type = TYPE; function Route(props) { var defaultProps; defaultProps = { handlerProps: {} }; this.props = merge(defaultProps, props); Route.__super__.constructor.call(this); } Route.prototype.propTypes = { handler: RouteDefinition.PropTypes.componentClass.isRequired, path: _atLeastOneUnlessDefault, name: _atLeastOneUnlessDefault, handlerProps: React.PropTypes.object.isRequired }; return Route; })(RouteDefinition); factory = function(props) { if (arguments.length > 1) { throw new Error('Route does not support children, use <Routes /> instead'); } return new Route(props); }; factory.type = TYPE; module.exports = factory;