-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
/
Copy pathIndexRedirect.js
49 lines (41 loc) · 1.14 KB
/
IndexRedirect.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import createReactClass from 'create-react-class'
import { string, object } from 'prop-types'
import warning from './routerWarning'
import invariant from 'invariant'
import Redirect from './Redirect'
import { falsy } from './InternalPropTypes'
/**
* An <IndexRedirect> is used to redirect from an indexRoute.
*/
/* eslint-disable react/require-render-return */
const IndexRedirect = createReactClass({
displayName: 'IndexRedirect',
statics: {
createRouteFromReactElement(element, parentRoute) {
/* istanbul ignore else: sanity check */
if (parentRoute) {
parentRoute.indexRoute = Redirect.createRouteFromReactElement(element)
} else {
warning(
false,
'An <IndexRedirect> does not make sense at the root of your route config'
)
}
}
},
propTypes: {
to: string.isRequired,
query: object,
state: object,
onEnter: falsy,
children: falsy
},
/* istanbul ignore next: sanity check */
render() {
invariant(
false,
'<IndexRedirect> elements are for router configuration only and should not be rendered'
)
}
})
export default IndexRedirect