Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

128
Views
React.JS pass state to link, props.location.state is undefined

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'}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Pass routeProps in Route like this.

<Route exact path="/private/orders" name="Orders" component={(routeProps) => <PrivateOrders {...routeProps} />} />

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!