Router: passing props with redirect component

Created on 18 Dec 2018  路  4Comments  路  Source: reach/router

Think you found a bug?

Have a question?

Hello I couldn't find any documentation about passing props with redirect like this is react-router

<Redirect to={{
            pathname: '/order',
            state: { id: '123' }
        }}
/>
needs docs question

Most helpful comment

Seems like it's possible to do this :
<Redirect to="/order" state={{ id: '123' }} />
Under the hood, the state is passed to navigate.
https://github.com/reach/router/blob/28a79e7fc3a3487cb3304210dc3501efb8a50eba/src/index.js#L465

the state can then be fetched in location.state.

Is it an intended feature ?

All 4 comments

Typically, with Redirect, you can think of it as popping a view of the stack, in which there would be no state to pass. If wanting to redirect but bring state, then navigate would probably suit you better.

Good insight though, in that the docs should point out these differences 馃

whoops, reopening so the docs can reflect the convo.

Thank you for this. This will be helpful. Appreciate the response. :)

Seems like it's possible to do this :
<Redirect to="/order" state={{ id: '123' }} />
Under the hood, the state is passed to navigate.
https://github.com/reach/router/blob/28a79e7fc3a3487cb3304210dc3501efb8a50eba/src/index.js#L465

the state can then be fetched in location.state.

Is it an intended feature ?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

magnusarinell picture magnusarinell  路  3Comments

thupi picture thupi  路  4Comments

EJIqpEP picture EJIqpEP  路  4Comments

florian-bd picture florian-bd  路  3Comments

ryanflorence picture ryanflorence  路  4Comments