jaredpalmer / after.js

Next.js-like framework for server-rendered React apps built with React Router
https://npm.im/@jaredpalmer/after
MIT License
4.13k stars 201 forks source link

How to prevent calling getInitialProps when follow the nested route? #540

Open Volodymyrkohut opened 2 years ago

Volodymyrkohut commented 2 years ago

❓Question

when I follow nested route like in example below, I don't want to every time call getInitialProps (because this is a modal, and I don't need every time fetch data )

Page with getInitialProps has Promise.all with 3 promises in it (requests), When I open modal or close I always got these 3 requests

Is there a way to prevent calling getInitialProps when change a route?

thank you

code from readme.md `// ./src/Detail.js import React from 'react'; import { Route } from 'react-router-dom';

class Detail extends React.Component { // Notice that this will be called for // /detail/:id // /detail/:id/more "don't want to call getInitialProps" // /detail/:id/other "don't want to call getInitialProps" static async getInitialProps({ req, res, match }) { const item = await CallMyApi(/v1/item${match.params.id}); return { item }; }

render() { return (

Detail

{this.props.item}
{this.props.item.more}
} />
{this.props.item.other}
} />
);

} }

export default Detail;`