React-router's route jump causes the data in the store to be reset

1. The cause of the problem:

        The React-router in the project is a first-level route. When the route jumps, the component will be uninstalled. When the component is returned, the component is rebuilt. The componentdidmount will reset the data in the store, but it cannot be embedded. Set of routes, nested routes will render all the components to the route. If you put the function that loads the store in the parent component, when you refresh the browser on this page, you will not find the data and report an error.

Second, the solution:

       The current component listens to the browser refresh event. When it is the browser refresh event, it does not reset the data in the store. When it initializes, it resets the data in the store.

Published 35 original articles · won praise 1 · views 6718

Guess you like

Origin blog.csdn.net/qq_36162529/article/details/104637181