wouter
wouter copied to clipboard
How can I use component Route with multiple paths?
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?
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 I saw custom parses but I'm not clear how to allow arrays...have you a code example? really appreciate it!
One of the options is to actually provide a custom regexp:
<Route path={/\/company|\/fr\/enterprise/i}>
...
</Route>