Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Routing with URL Link as params

How can i set route like this.

<Route path='/:id/:url' component={Url}/>

and then in Url component access the value of this url like.

const url = this.props.params.match.url

so if i pass in http://localhost:3000/245/http://www.msn.com

i would be able to get this url value through props.params.

like image 848
Malik Awan Avatar asked Sep 01 '26 16:09

Malik Awan


1 Answers

You can encode your URL to remove the slashes and other URL specific symbols using encodeURIComponent

So for your case, it'll be const urlEncoded = encodeURIComponent(http://www.msn.com) then passing this value to your URL should result to http://localhost:3000/245/http%3A%2F%2Fwww.msn.com which you can access using this.props.params.match.url

like image 149
kimobrian254 Avatar answered Sep 05 '26 02:09

kimobrian254



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!