0

In react router v5, I know the way to add optional route param in route path,

<Route path="/type/:typeId?" />

But is there a way to show optional search param(?search=test&page=1) in route path?

saranya
  • 11
  • 2
  • Are you trying to select a different Route based on the query parameters? I don't think React Router supports that. – jonrsharpe Oct 10 '20 at 11:18
  • No. I want to render the component based on the pull location path ie. – saranya Oct 10 '20 at 13:42
  • I don't know what you mean by pull location path. The path is `/type/:typeId`, the query parameters are `?search=foo&page=1` - the router uses the path to determine the route, if you want the query params you can access them in the rendered component with e.g. https://stackoverflow.com/q/35352638/3001761. – jonrsharpe Oct 10 '20 at 13:44
  • My question is, is it possible to mention searchparams in route path? what i want is, here search and page is optional, i want to say that, with or without those params in route render the component. Any idea? – saranya Oct 10 '20 at 16:09
  • No, it's not. If you want to *access* query parameters look at https://reactrouter.com/web/example/query-parameters – jonrsharpe Oct 10 '20 at 16:16

0 Answers0