forked from remix-run/react-router
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes remix-run#1966
- Loading branch information
Showing
7 changed files
with
98 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import React from 'react' | ||
import invariant from 'invariant' | ||
import warning from 'warning' | ||
import Redirect from './Redirect' | ||
import { falsy } from './PropTypes' | ||
|
||
const { string, object } = React.PropTypes | ||
|
||
/** | ||
* An <IndexRedirect> is used to redirect from an indexRoute. | ||
*/ | ||
const IndexRedirect = React.createClass({ | ||
|
||
statics: { | ||
|
||
createRouteFromReactElement(element, parentRoute) { | ||
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 | ||
}, | ||
|
||
render() { | ||
invariant( | ||
false, | ||
'<IndexRedirect> elements are for router configuration only and should not be rendered' | ||
) | ||
} | ||
|
||
}) | ||
|
||
export default IndexRedirect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/*eslint-env mocha */ | ||
import expect from 'expect' | ||
import React from 'react' | ||
import createHistory from 'history/lib/createMemoryHistory' | ||
import IndexRedirect from '../IndexRedirect' | ||
import Router from '../Router' | ||
import Route from '../Route' | ||
|
||
describe('An <IndexRedirect>', function () { | ||
|
||
let node | ||
beforeEach(function () { | ||
node = document.createElement('div') | ||
}) | ||
|
||
afterEach(function () { | ||
React.unmountComponentAtNode(node) | ||
}) | ||
|
||
it('works', function (done) { | ||
React.render(( | ||
<Router history={createHistory('/')}> | ||
<Route path="/"> | ||
<IndexRedirect to="/messages" /> | ||
<Route path="messages" /> | ||
</Route> | ||
</Router> | ||
), node, function () { | ||
expect(this.state.location.pathname).toEqual('/messages') | ||
done() | ||
}) | ||
}) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters