Skip to content

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

@Volodymyrkohut

Description

@Volodymyrkohut

❓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;`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions