Skip to content

Commit

Permalink
[fixed] <Redirect> handling
Browse files Browse the repository at this point in the history
[added] <Redirect query>
[added] <Redirect state>
  • Loading branch information
mjackson committed Jun 15, 2015
1 parent 3a8d1eb commit 824ed63
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions modules/Redirect.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React from 'react';
import invariant from 'invariant';
import { createRouteFromReactElement } from './RouteUtils';
import { formatPattern } from './URLUtils';
import { falsy } from './PropTypes';

var { string } = React.PropTypes;
var { string, object } = React.PropTypes;

export var Redirect = React.createClass({

Expand All @@ -15,8 +16,15 @@ export var Redirect = React.createClass({
if (route.from)
route.path = route.from;

route.onEnter = function (nextState, router) {
router.replaceWith(route.to, nextState.query);
route.onEnter = function (nextState, transition) {
var { location, params } = nextState;
var pathname = route.to ? formatPattern(route.to, params) : location.pathname;

transition.to(
pathname,
route.query || location.query,
route.state || location.state
);
};

return route;
Expand All @@ -25,8 +33,11 @@ export var Redirect = React.createClass({
},

propTypes: {
from: string,
path: string,
from: string, // Alias for path
to: string.isRequired,
query: object,
state: object,
onEnter: falsy,
children: falsy
},
Expand Down

0 comments on commit 824ed63

Please sign in to comment.