Keep components between routes using react-router

后端 未结 2 507
Happy的楠姐
Happy的楠姐 2021-01-05 17:57

I have a multi-steps form and I\'m using react-router to navigate between the different steps. In some of the steps I show an iframe to the user. When the u

2条回答
  •  一生所求
    2021-01-05 18:16

    Quite simply, there's no way to preserve a component in the render tree if the parent is not rendered. That is, when the route changes, your component will necessarily be unmounted if it's a child to a Route.

    One way to side-step that is to make your component not a child to any Route at all. This way, you would always render this component alongside every Route. Then you can simply use styles to show/hide it when appropriate. Obviously, this will partly compromise the structure of your DOM.

提交回复
热议问题