0

I have such code:

const SEARCH_FORM_PAGES = [ 
  'project/:projectGuid',
  'analysis_group/:analysisGroupGuid',
  'family/:familyGuid',
]

const VariantSearch = ({ match }) =>
  <Switch>
    <Route path={SEARCH_FORM_PAGES.map(pagePath => `${match.url}/${pagePath}`)} component={VariantSearchForm} />,
  </Switch>

Now I want to match an array in the project/:projectGuid url instead of just a single parameter :projectGuid, is it possible? I would have such a url for instance: project/F001_D1K2,F002_D1K3,F003_D2K5 and I want the part F001_D1K2,F002_D1K3,F003_D2K5 to be matched and converted into an array projects which I would be able to get in the VariantSearchForm component.

1 Answer 1

1

you can send multiple params like this:

/project?items=F001_D1K2&items=F002_D1K3&items=F003_D2K5

and then, make it to array, using query-string library:

import qs from "query-string";
import { useLocation } from "react-router-dom";

const VariantSearchForm = () => {
  const { search } = useLocation;
  const parsed = qs.parse(search);
  console.log(parsed.items);
  // => ["F001_D1K2", "F002_D1K3", "F003_D2K5"]
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.