2

How can I set up multiple Paths to one element with Routers?

It used to be like:

<Route path = {['example1','example2',...,'exampleN']} element = {<Test />} />

How do I get the same result in the newest Version?

Allleex
  • 137
  • 9
  • Does this answer your question? [having multiple paths to the same component in react-router-dom v6](https://stackoverflow.com/questions/70228810/having-multiple-paths-to-the-same-component-in-react-router-dom-v6) – Źmicier Jaraševič Dec 07 '21 at 15:36
  • Does this answer your question? [Multiple path names for a same component in React Router](https://stackoverflow.com/questions/40541994/multiple-path-names-for-a-same-component-in-react-router) – Ben Smith Jan 14 '22 at 01:05

1 Answers1

1

You can map over the array to create the Route elements:

{["/", "/home"].map((path, index) => {
        return (
          <Route path={path} element={
              <PageWrapper>
                <Home />
              </PageWrapper>
            }
            key={index}
          />
        );
      })}