Languages
[Edit]
EN

React / react-router - route respond to multiple paths

0 points
Created by:
chelsea
746

In this article, we would like to show you how to set Route to respond to more than one paths in react-router.   

Quick solution: 

<Route path="/(path1|path2)/" component={component} />

Practical example:

import { Route } from 'react-router-dom';

const App = () => {
    // Some code...
    
    <Route path='/(home|faq)/' component={Home} />;
};

Home component is rendered for the '/home' and '/faq' paths.

Alternative titles

  1. React / react-router - two paths in one Route
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

React - react-router

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join