-
Notifications
You must be signed in to change notification settings - Fork 27k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Application Layout? #71
Comments
Just an idea: you may consider to write an higher order component that takes your page component and returns some structure like this <section>
<Header />
<YourPageComponent />
<Footer />
</section> Update:
import React, { Component } from 'react';
import { Header, Footer } from 'components';
const withAppLayout = () => (ComposedComponent) => {
class AppLayout extends Component {
render() {
return (
<section>
<Header />
<ComposedComponent {...this.props} />
<Footer />
</section>
);
}
}
return AppLayout;
};
export default withAppLayout;
import withAppLayout from 'components/AppLayout';
const Home = () => (<div>Home</div>);
export default withAppLayout(Home); |
Thank you for your reply 😃 . Where would I specify this HOC in the context of next.js though? The default router will render index.js
about.js
|
@davidrossjones one option is: // components/Layout.js
export default () => (
<div>
<h1>Header</h1>
{this.props.children}
<footer>the footer</footer>
</div>
) // pages/index.js
import Layout from '../components/Layout'
export default () => (
<Layout>
<p>Home</p>
</Layout>
) // pages/about.js
import Layout from '../components/Layout'
export default () => (
<Layout>
<p>About</p>
</Layout>
) |
Aha! That makes perfect sense. Thank you @altayaydemir and @impronunciable for the insight! Awesome. 👍 |
@impronunciable @altayaydemir Apparently, the Layout wrapper component gets re-mounted when changing routes which does not completely solve the problem. @ericf describes this in #50. |
@dlindenkreuz well, you are right. 😥 I also agree on having an app layout component. |
how to get initial props using this layout? like this
|
I was wondering the same thing as well. Is there anything fundamentally different between pages and containers? |
Wondering the same over here. I was used more to.
And then on.
where compose can be something like https://github.com/arunoda/react-komposer, but still i'm not sure if this the correct usage for NextJs, or i can avoid the Container and do this on the Page directly |
You could use |
In the React context, when building an app I'm used to the concept of containers and components. It appears to me that "pages" are somewhat equivalent to containers within next.js.
Is there a recommended way to add an application layout container such that I could specify for example global
<Header/>
and<Footer/>
components with the router determining which content to display within (the page)? Similar to how the popularreact-router
packagematch
function can be configured on the server.Using the next.js default router and pages folder as is, to achieve this do I have no option but to duplicate
<Header/>
and<Footer/>
across all pages?The text was updated successfully, but these errors were encountered: