Skip to content
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

Sub pages? (for rendering partials and child routes) #75

Closed
mmmeff opened this issue Oct 26, 2016 · 9 comments
Closed

Sub pages? (for rendering partials and child routes) #75

mmmeff opened this issue Oct 26, 2016 · 9 comments

Comments

@mmmeff
Copy link

mmmeff commented Oct 26, 2016

Is there currently any way to render partials? For example, how would one go about adding a component to the application without having to tack it onto each and every file in the pages directory?

@mmmeff mmmeff changed the title Page templating? (Sub-routing, partial rendering) Sub pages? (for rendering partials and child routes) Oct 26, 2016
@nodegin
Copy link
Contributor

nodegin commented Oct 26, 2016

try to create a components folder and place your items inside

@nkzawa
Copy link
Contributor

nkzawa commented Oct 26, 2016

related: #50

@dlindenkreuz
Copy link
Contributor

@mmmeff Reusable components that are not relevant to the router can reside outside the pages directory. Check out the examples [1] [2].

@mmmeff
Copy link
Author

mmmeff commented Oct 26, 2016

@dlindenkreuz @nodegin I believe you may have misinterpreted my question.

What I'm asking for is not how to split components out, but rather how I can avoid adding the same components to every single page if they are shared layout elements, such as a page's navigation bar, footer, etc.

I've implemented the following example of a workaround I have for now and pushed it here: https://github.com/mmmeff/nextjs-page-template-example

It also shows how you can apply a CSS reset across your entire application without needing to require('glamor/reset') on every page.

@dlindenkreuz
Copy link
Contributor

@mmmeff Point taken! I'm currently discussing this with @ericf in issue #50 and suggested a modifiable top-level App component in #88. This would also solve your problem, right?

@mmmeff
Copy link
Author

mmmeff commented Oct 27, 2016

@dlindenkreuz Yup! A top-level component would solve many issues at once with Next - it seems to be a fairly severe limitation in the framework at the moment, of which the impact is only marginally mitigated by the inclusion of next/head

@rauchg
Copy link
Member

rauchg commented Jan 10, 2017

For reference to those who find this issue:

  • Top level components are solved by wrapping in HOC (see layout examples inside ./examples)
  • For SSR output, you can now supply a custom <Document /> (see README)

@rauchg rauchg closed this as completed Jan 10, 2017
@krazyjakee
Copy link

krazyjakee commented Mar 21, 2018

@rauchg this can't be solved if the layout is is remounted with every navigation right? That can't be an acceptable solution to this problem.

Unless I'm missing something. How can the layouts ensure only the child components are remounted, keeping the layout intact?

@kafkahw
Copy link

kafkahw commented Sep 20, 2018

@krazyjakee here's my guess.
The reconciliation process in react will handle it. It detects the difference between two react trees and if the component is the same it'll skip remounting or re-rendering if there's no props/state changes. That way if all routes are using the same top-level component, there won't be a top-level remount if you switch routes.

ijjk pushed a commit to ijjk/next.js that referenced this issue Apr 13, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Sep 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants