You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
i discovered the new NextJs functionality of static pages and need to say that this is a huge customer benefit in terms of performance.
In my project i provide multiple static pages where i get the content from a CMS system - /impress, /about-us or /contact.
At the same time i've a catch all route for other pages ( we can consider this as product pages ) that are reachable via /product1, /product2 etcpp.
The catch all page fetches the content inside getInitialProps and i cannot mix static pages with getInitialProps.
My idea is that i render the catch all page as fallback in the static page, but if i import the catch all page and render it, the getInitialProps is not executed and therefore not product data to display.
For the static pages i use a file /pages/[static].js:
// i tried this
// const FallbackPage = dynamic(() => import('./[...index]'));
const StaticPage = (props) => {
const router = useRouter();
if (router.isFallback) {
// return <FallbackPage />
}
return (
<div>CMS Data</div>
);
};
export default StaticPage;
export async function getStaticPaths() {
return {
// Only `/posts/1` and `/posts/2` are generated at build time
paths: [
{ params: { static: 'impress' } },
{ params: { static: 'about-us' } },
],
fallback: true,
};
}
export async function getStaticProps({ params }) {
// CMS connection logic
const props = {
props: {
....
},
};
return props;
}
For the Product Pages i use a catch all page /pages/[...index].js:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
i discovered the new NextJs functionality of static pages and need to say that this is a huge customer benefit in terms of performance.
In my project i provide multiple static pages where i get the content from a CMS system -
/impress
,/about-us
or/contact
.At the same time i've a catch all route for other pages ( we can consider this as product pages ) that are reachable via
/product1
,/product2
etcpp.The catch all page fetches the content inside
getInitialProps
and i cannot mix static pages with getInitialProps.My idea is that i render the catch all page as fallback in the static page, but if i import the catch all page and render it, the
getInitialProps
is not executed and therefore not product data to display.For the static pages i use a file
/pages/[static].js
:For the Product Pages i use a catch all page
/pages/[...index].js
:Any alternative idea or could this even be a new feature to next.js - "Render catchAll routes as fallback in static pages"
Thanks a lot.
Beta Was this translation helpful? Give feedback.
All reactions