-1

http://localhost:8080/?companyKey=eefef-edd-dd-ddf

I want to pass the company key in my react project via URL

I used this method

<Route exact path="/?companyKey=key"component={CompanySelectorFromKey} />

the method isn't working

Theepag
  • 301
  • 2
  • 16
  • Are trying to grab the `companyKey` parameters from the URL and render this ``? Or are you trying to figure out how to get your `CompanySelectorFromKey` component to read the `companyKey` parameter? – codemonkey Jan 04 '21 at 06:27
  • Does this answer your question? [React - How to get parameter value from query string?](https://stackoverflow.com/questions/35352638/react-how-to-get-parameter-value-from-query-string) – brc-dd Jan 04 '21 at 06:29
  • I have to view that company key from the URL in CompanyKeySelecterFromKey Comonent – Theepag Jan 04 '21 at 06:29
  • @brc-dd nope, please answer it simple – Theepag Jan 04 '21 at 07:02

2 Answers2

1

<Route path='/edit/:id' component={Edit} />

And in edit component you are received this id by

let id = props.match.params.id;

codemonkey
  • 7,325
  • 5
  • 22
  • 36
kshamata
  • 61
  • 4
0

The way to pass parameters into a Route is like this <Route exact path="/:companyKey" component={CompanySelectorFromKey} />

Then in your CompanySelectorFromKey, you can read that parameter like so:

const company_key = props.match.params.companyKey;

So your page would actually have to be accessed this way:

http://localhost:8080/eefef-edd-dd-ddf

Here is a working Sandbox: https://codesandbox.io/s/gracious-sky-jp8rv?file=/src/App.js

Try accessing the preview side like this:

https://jp8rv.csb.app/eefef-edd-dd-ddf

and you will see the magic.

codemonkey
  • 7,325
  • 5
  • 22
  • 36
  • Thanks bro, is there any way to access via this way ! http://localhost:8080/?companyKey=eefef-edd-dd-ddf – Theepag Jan 04 '21 at 07:32
  • @Theepag I have updated the Sanbox to work the way you want. You can access it this way now: https://jp8rv.csb.app/?companyKey=17212712321 – codemonkey Jan 04 '21 at 07:47