Skip to content

Add Constrainable mixin #67

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed

Add Constrainable mixin #67

wants to merge 2 commits into from

Conversation

bjyoungblood
Copy link

Replaces #52

Allows your route handlers to place constraints on the path and/or params they will handle and redirects to another route if the constraints do not match.

Usage:

var UserEditHandler = React.createClass({
  mixins      : [ Constrainable ],

  statics : {
    redirectTo : '404',
    pathConstraints : /^\/user\/123\/(create|edit)$/
  },

  render : function() { return React.DOM.div(); }
});

var PageEditHandler = React.createClass({
    mixins : [Constrainable],
    statics : {
        redirectTo : '404',
        paramConstraints : {
            pageId : /^[A-Za-z]+$/,
            action : /^\d+$/
        },
    },
    render : function() { return React.DOM.div(); }
});

React.renderComponent(
    <Route handler={SiteWrapper}>
        <Route path='/user/:userId/:action' handler={UserEditHandler} />
        <Route path='/page/:pageId/:action' handler={PageEditHandler} />
    </Route>,
    document.body
);

@ryanflorence
Copy link
Member

@bjyoungblood any reason not to just publish this to your own github account and npm?

@bjyoungblood
Copy link
Author

@bjyoungblood bjyoungblood deleted the feature/constrainable-mixin branch July 2, 2014 18:01
@ryanflorence
Copy link
Member

@lock lock bot locked as resolved and limited conversation to collaborators Jan 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants