Skip to content

Commit 824ed63

Browse files
committed
[fixed] <Redirect> handling
[added] <Redirect query> [added] <Redirect state>
1 parent 3a8d1eb commit 824ed63

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

modules/Redirect.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import React from 'react';
22
import invariant from 'invariant';
33
import { createRouteFromReactElement } from './RouteUtils';
4+
import { formatPattern } from './URLUtils';
45
import { falsy } from './PropTypes';
56

6-
var { string } = React.PropTypes;
7+
var { string, object } = React.PropTypes;
78

89
export var Redirect = React.createClass({
910

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

18-
route.onEnter = function (nextState, router) {
19-
router.replaceWith(route.to, nextState.query);
19+
route.onEnter = function (nextState, transition) {
20+
var { location, params } = nextState;
21+
var pathname = route.to ? formatPattern(route.to, params) : location.pathname;
22+
23+
transition.to(
24+
pathname,
25+
route.query || location.query,
26+
route.state || location.state
27+
);
2028
};
2129

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

2735
propTypes: {
28-
from: string,
36+
path: string,
37+
from: string, // Alias for path
2938
to: string.isRequired,
39+
query: object,
40+
state: object,
3041
onEnter: falsy,
3142
children: falsy
3243
},

0 commit comments

Comments
 (0)