'React Routing Variable in the link

I am trying to use react router to redirect to a different page, however the problem I have is that I have to put a variable inside and I can't make it to work.

Here is what I have (in the code section):

The ":id" part of the URL has to be ignored because it's populated from the database, that is why I need to use a variable that is passed from the server.

The problem is that when I put something like {variable} inside "" or without it doesn't work.

<Switch> <Route exact path="/Page1/:id/Page2" component={Component} /> <Route path="/Page1/:id/Page2/Page3" component={Component1} /> </Switch>

I want to use the variable so that it takes it and links correctly.

Can you please tell me if you know how to help with this problem?



Solution 1:[1]

  1. I think you can make use of URL parameters and achieve what you are looking for.
    1. I assume that this can also be fixed by defining the association between the two entities of the database which you are trying to fetch. I hope you are more or less trying to address a Header---Items scenario.

Regards Pavan Bhamidipati

Solution 2:[2]

There are two methods to insert variable inside url. You can try either of them.

<Route exact path=`/Page1/${variable}/Page2` component={Component} /> 

or

<Route exact path={'/Page1/'+variable+'/Page2} component={Component} /> 

Solution 3:[3]

I made it work by inserting variable as

<Link to={`/getItemsFromCart/${variable}`} >
   Cart
</Link>

Solution 4:[4]

You have two issues:

First, the thread that executes main modifies p.ii and p.jj without holding the mutex. So when the thread you created goes to read ii and jj, anything can happen because they may be in the process of being modified.

Second, it's not clear what behavior you expect and why. The output you see is perfectly reasonable. You say it's "wrong" but don't explain why it's wrong. You don't force any ordering between the thread running main and the printing threads. The thread running main might manage to change ii and jj several times before the thread created manages to run.

Why do you think two threads printing the same thing is "wrong"? What do you think forces the first thread to finish before the main thread modifies ii and jj more than once?

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Pavan Bhamidipati
Solution 2 sarru1291
Solution 3 rubal islam
Solution 4 David Schwartz