Skip to content

Instantly share code, notes, and snippets.

@ryanflorence
Created December 16, 2014 23:48
Show Gist options
  • Save ryanflorence/c1fe013af753456c1ca9 to your computer and use it in GitHub Desktop.
Save ryanflorence/c1fe013af753456c1ca9 to your computer and use it in GitHub Desktop.
var Authenticated = React.createClass({
statics: {
willTransitionTo (transition) {
if (!authenticated()) {
transition.redirect('login');
}
}
}
});
var routes = (
<Route handler={App}>
<Route handler={Authenticated}>
// put all authenticated routes here, since we don't require
// paths on routes, it won't mess with the url
</Route>
<Route handler={Public}>
// ...
</Route>
</Route>
);
@markdalgleish
Copy link

👍

@uberllama
Copy link

I assume you meant:

var Authenticated = React.createClass({
  statics: {
    willTransitionTo: function(transition) {
      if (!authenticated()) {
        transition.redirect('login');
      }
    }
  }
});

In which case you get Uncaught Error: Invariant Violation: createClass(...): Class specification must implement arendermethod. :(

@jtangelder
Copy link

Returning a RouteHandler will work.

render() {
    return <RouteHandler />
  }

@mbektimirov
Copy link

In this case routes order make sense. Authenticated handler will block Public group when auth hasn't been done yet as it intercepts the routing flow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment