Nested pages not loading static files using HOC
See original GitHub issueBug report
Describe the bug
The static images in my layout file (Navbar & Footer) will not get loaded when exporting html and navigating into a nested page (pages/products/test.js). But they are loaded when navigating into files directly (pages/*.js).
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
- Install freshly NextJS
- Create Layout HOC
- next build && next export && serve -p 8080
- localhost:8080 //Images loaded
- localhost:8080/products/test // HOC images missing
components/Layout.js
const withLayout = Content => {
return () => (
<Container>
<Navbar active={Content.displayName} />
<Content />
<Footer />
</Container>
);
};
export default withLayout;
pages/index.js
// IMAGES WILL LOAD HERE (i.e. Logo in Navbar)
render() {
return (
<p>Test</p>
);
}
}
Home.displayName = "Home";
export default withLayout(Home);
pages/products/test.js
// IMAGES SET IN Layout.js WILL NOT BE LOADED
// test.jpg WILL BE LOADED
render() {
return (
<img src={"../../static/test.jpg"} />
);
}
}
Home.displayName = "Home";
export default withLayout(Home);
Expected behavior
Images set in Layout file for Navbar & Footer should be loaded when navigating into a nested page.
Screenshots


Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (2 by maintainers)
Top Results From Across the Web
Nested pages not loading static files using HOC - Stack Overflow
I solved this by creating & overwriting the file ./pages/_app.js . The Layout it now living there and will not be rerendered on...
Read more >Nested pages not loading static files using HOC-Reactjs
[Solved]-Nested pages not loading static files using HOC-Reactjs. Search. score:1. Accepted answer. import React from "react"; import App, ...
Read more >Basic Features: Layouts - Next.js
Learn how to share components and state between Next.js pages with Layouts. ... Because this file is not a Page, you cannot use...
Read more >Higher-Order Components - React
A higher-order component (HOC) is an advanced technique in React for reusing component logic. HOCs are not part of the React API, per...
Read more >Lazy loading React components - LogRocket Blog
When you visit a website or use an app, it's very likely you're not seeing all the available content. Depending on how you...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Ran into the same issue, but nothing here worked for me. At the end, it turned out a div with
height: 100vh;was causing the issue. Pages are now rendered scrolled to the top after that line is removed.
I’ve stuck for two days. My solution is to remove
overflow-x: hiddenin body, HTML. Check your css such as min-height, overflow …