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

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

Open
Volodymyrkohut opened this issue Jun 1, 2022 · 0 comments

Comments

@Volodymyrkohut
Copy link

❓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}
<Route
path="/detail/:id/more"
exact
render={() =>
{this.props.item.more}
}
/>
<Route
path="/detail/:id/other"
exact
render={() =>
{this.props.item.other}
}
/>

);
}
}

export default Detail;`

@Volodymyrkohut Volodymyrkohut changed the title How to prevent call getInitialProps when follow the nested route? How to prevent calling getInitialProps when follow the nested route? Jun 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant