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

190
Views
React router dom with Typescript using match

I am using React Router Dom version 5 with React v 17 and with TypeScript. I am trying to figure out how to use the match object. So far I have:

import { BrowserRouter, Route, Switch, match } from 'react-router-dom';


interface DetailsProps {
  match?: match<string> ;
}

const Routing: React.FunctionComponent<DetailsProps> = (props: DetailsProps) => {
   const match = props.match;

   // more routes here
   <Route path={`${match.url}`} render={() => <Component/>} />
}

I get there error: Object is possibly 'undefined'.

Any Idea's why? is the type wrong?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can import it:

import { match } from 'react-router-dom';
about 4 years ago · Juan Pablo Isaza Report

0

Your interface says that match is an optional param and can be undefined

interface DetailsProps {
  match?: match<string> ;
}

By removing ? mark you'll make it required:

interface DetailsProps {
  match: match<string> ;
}
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!