<h1 dir="auto">Feature request</h1>
<h2 dir="auto">Is your feature request related to a problem? Please describe.</h2>
<p dir="auto">There are directories in "pages" whose contents should all have the same layout. For example, an "articles" directory might have articles written in .mdx, which compile to react elements. It would be very useful for all the .mdx files under "articles" to have the same layout and shared logic.</p>
<h2 dir="auto">Describe the solution you'd like</h2>
<p dir="auto">Ideally, one could create an _app.js file for each directory. All files in that directory would use that _app.js. Files in other directories with no custom app would use pages/_app.js if that file exists.</p>
<h2 dir="auto">Describe alternatives you've considered</h2>
<p dir="auto">All the alternatives I've thought of seem to have the same problem, that the routing information needs to be written in code somewhere, in addition to next inferring that from the filesystem, which is redundant. For example, you could just have a single pages/_app.js and some logic in there to figure out which layouts to add to what. This makes it required to write out your routes in the _app.js file. It's basically a router inside a router, so it's not the best solution.</p>
<p dir="auto">Another alternative is to keep the .mdx files (or react components) somewhere outside of "pages", and import them in pages/articles.jsx for example. Then, essentially implement a router that shows the proper component depending on the route. Again, you're basically implementing a router within a router.</p>
<h2 dir="auto">Additional context</h2>
<p dir="auto">I'm new to next, so if there's something obvious I'm missing, I apologize.</p>
<p dir="auto"><strong>Edit July 2021:</strong> The layouts example has been updated to persist state across page transitions: <a href="https://github.com/vercel/next.js/tree/canary/examples/layout-component">https://github.com/vercel/next.js/tree/canary/examples/layout-component</a></p>