How to buy a condom

I had a simple task to accomplish: to go out and buy a pack of condoms. And I didn’t know how to go about it. In my home country, this would have been an impossible task. I would get ugly looks from…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




URL Parameters with React Router

URL parameters are a fundamental aspect of React Router and a fundamental aspect of building web applications. In this post, we’ll break down the “URL Parameters” example on the React Router documentation to learn how you to effectively leverage URL parameters in your React app.

URL parameters are parameters whose values are set dynamically in a page’s URL. This allows a route to render the same component while passing that component the dynamic portion of the URL so it can change based off of it.

Then the Profile component would be able to access the dynamic handle from props.match.params.handle.

Let’s look at the example from the React Router docs now. First, we’ll need to import the components we’ll need and build a navbar. We’ll be navigating between the /netflix, /zillow-group, /yahoo, and /module-create paths.

Each of those paths are going to render the same Child component which will just show the URL parameter’s value (which we’ll call id).

Now we have our navbar and the component to render, the only thing left to do is to render a Route with a URL paramter.

And that’s it. Because we’re using URL parameters, we can have four different paths render the exact same component and that component will be passed the URL parameter (in this case id) as a prop.

Add a comment

Related posts:

A Meditation on a Scene

Three figures pose for a shot. Who are these figures? There is the psychoanalyst, Lou Salome, and then the two philosophers, Nietzsche to the right and between them, Paul Ree. The photographic…

Using static typing to protect against code injection attacks

Code injection attack is a method of taking advantage of a flaw where an application can be tricked to relay malicious code from a system to another system which then executes it. Common examples of…

How can the way you think save you from death?

I solemnly swear to tell you the truth, the whole truth and nothing but the truth. How many of you can say your actively trying to find the truth? Probably not many. This was me once. I swore to…