Skip to content

fix #6168 #6169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 23, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions packages/react-router/docs/api/Redirect.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,21 @@ The URL to redirect to. Any valid URL path that [`path-to-regexp@^1.7.0`](https:
All URL parameters that are used in `to` must be covered by `from`.

```jsx
<Redirect to="/somewhere/else"/>
<Redirect to="/somewhere/else" />
```

## to: object

A location to redirect to. `pathname` can be any valid URL path that [`path-to-regexp@^1.7.0`](https://github.com/pillarjs/path-to-regexp/tree/v1.7.0) understands.

```jsx
<Redirect to={{
pathname: '/login',
search: '?utm=your+face',
state: { referrer: currentLocation }
}}/>
<Redirect
to={{
pathname: "/login",
search: "?utm=your+face",
state: { referrer: currentLocation }
}}
/>
```

The `state` object can be accessed via `this.props.location.state` in the redirected-to component. This new `referrer` key (which is not a special name) would then be accessed via `this.props.location.state.referrer` in the `Login` component pointed to by the pathname `'/login'`
Expand All @@ -42,7 +44,7 @@ The `state` object can be accessed via `this.props.location.state` in the redire
When `true`, redirecting will push a new entry onto the history instead of replacing the current one.

```jsx
<Redirect push to="/somewhere/else"/>
<Redirect push to="/somewhere/else" />
```

## from: string
Expand All @@ -57,9 +59,7 @@ This can only be used to match a location when rendering a `<Redirect>` inside o
<Redirect from='/old-path' to='/new-path'/>
<Route path='/new-path' component={Place}/>
</Switch>
```

```jsx
// Redirect with matched parameters
<Switch>
<Redirect from='/users/:id' to='/users/profile/:id'/>
Expand Down