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.
Showing
6 changed files
with
77 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('./modules/components/Redirect'); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
API: `Redirect` (component) | ||
=========================== | ||
|
||
Configures a redirect for a path in your route declarations. | ||
|
||
Props | ||
----- | ||
|
||
### `from` | ||
|
||
The path you want to redirect from, including dynamic segments. | ||
|
||
### `to` | ||
|
||
The `name` of the route you want to redirect to. | ||
|
||
Example | ||
------- | ||
|
||
```xml | ||
<!-- | ||
lets say we want to change from `/profile/123` to `/about/123` | ||
and redirect `/get-in-touch` to `/contact` | ||
--> | ||
<Routes> | ||
<Route handler={App}> | ||
<Route name="contact" handler={Contact}/> | ||
<Route name="about-user" path="about/:userId" handler={UserProfile}/> | ||
</Route> | ||
|
||
<Redirect from="get-in-touch" to="contact" /> | ||
<Redirect from="profile/:userId" to="about-user" /> | ||
</Routes> | ||
``` | ||
|
||
Note that the `<Redirect/>` can be placed anywhere in the route | ||
hierarchy, if you'd prefer the redirects to be next to their respective | ||
routes. | ||
|
||
```xml | ||
<Routes> | ||
<Route handler={App}> | ||
<Route name="contact" handler={Contact}/> | ||
<Redirect from="get-in-touch" to="contact" /> | ||
</Route> | ||
</Routes> | ||
``` |
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 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,25 @@ | ||
var React = require('react'); | ||
var Route = require('./Route'); | ||
|
||
function Redirect(props) { | ||
return Route({ | ||
path: props.from, | ||
handler: createRedirectClass(props.to) | ||
}); | ||
} | ||
|
||
function createRedirectClass(to) { | ||
return React.createClass({ | ||
statics: { | ||
willTransitionTo: function(transition, params, query) { | ||
transition.redirect(to, params, query); | ||
} | ||
}, | ||
|
||
render: function() { | ||
return null; | ||
} | ||
}); | ||
} | ||
|
||
module.exports = Redirect; |