I am passing a state to the Link
component and trying to access the state using props.location.satate
. Unfortunately, the state is undefined. I have tried to send the state from the to
attribute using the pathname
and state
, still undefined.
<Route exact path="/private/orders" name="Orders" component={PrivateOrders} />
Private orders
import React from 'react'
const PrivateOrders = (props) => {
console.log(props)
return (
<div>
<h1>Orders</h1>
</div>
)
}
export default PrivateOrders
Link
<Link
to="private/orders"
state={{
x: "y",
y: "y",
z: "y",
i: "y",
>
<CButton color="primary">Order Now</CButton>
</Link>
result
location: {pathname: '/private/orders', search: '', hash: '', state: undefined, key: 'lt9bpr'}