M
M
Mirrrta2020-05-20 15:35:25
JavaScript
Mirrrta, 2020-05-20 15:35:25

How to make it so that on one page only the content changes depending on the router?

There is an inner page

<Switch>
<Route path={'/my'} component={My} />
<Route path={'/payments'} component={Payments} />
...
</Switch>


It is necessary that the My and Payments components have the same header and footer, I do not want to duplicate the code.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
paoluccio, 2020-05-20
@Mirrta

It is possible like this:

const PageLayout = ({ children }) => (
  <React.Fragment>
    <header>Header</header>
    {children}
    <footer>Footer</footer>
  </React.Fragment>
);

const Page = () => (
  <PageLayout>
    <Switch>
      <Route path='/my' component={My} />
      <Route path='/payments' component={Payments} />
    </Switch>
  </PageLayout>
);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question