Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

react router get data from url

// This Answer is taken from Here => https://flaviocopes.com/react-router-data-from-route/

////////////// first way ///////////////
////// Route ///////
<Route path="/project/:id">
  <SingleProject />
</Route>
////// SingleProject Component ///////
import { useHistory, useParams } from 'react-router-dom'

export default function SingleProject(){
	const id = useParams().id;
}

////////////// second way ///////////////
////// Route ///////
<Route path="/project/:id" render={(props) => <SingleProject {...props} />} />
////// SingleProject Component ///////
export default function SingleProject(props) {
	const id = props.match.params.id
}

Source by flaviocopes.com #
 
PREVIOUS NEXT
Tagged: #react #router #data #url
ADD COMMENT
Topic
Name
5+8 =