wouter icon indicating copy to clipboard operation
wouter copied to clipboard

How can I use component Route with multiple paths?

Open about-daniel opened this issue 1 year ago • 3 comments

Hi everyone! I'm wondreing if there's a way to use multiple paths from Route component? Something like that:

 <Route path={["/company","/fr/entreprise"]}>
      ...
 </Route>

Anyone can help me pls?

about-daniel avatar Aug 09 '24 08:08 about-daniel

Take a look at custom parsers (see Strict Routes in the FAQ section). You can define your own function that will extend current behavior to accept arrays and then join two regular expressions into one.

molefrog avatar Aug 09 '24 09:08 molefrog

@molefrog I saw custom parses but I'm not clear how to allow arrays...have you a code example? really appreciate it!

about-daniel avatar Aug 09 '24 13:08 about-daniel

One of the options is to actually provide a custom regexp:

 <Route path={/\/company|\/fr\/enterprise/i}>
      ...
 </Route>

molefrog avatar Aug 21 '24 14:08 molefrog