React-native-router-flux: componentWillUnmount is not triggered when a new route is pushed

Created on 18 Jan 2016  路  7Comments  路  Source: aksonov/react-native-router-flux

Might be related to #91
I know component is unmounted when the type of the route is "replace", but I need to set type="push" so that I can set Animations...

When type is push, the component is not unmounted. What can I do ?

Thank you ;)

Most helpful comment

Run into the same issue, had my head scratching, setting type='replace' fixed it.

<Route name="dashboard" type='replace' wrapRouter={false} component={Dashboard} title="Dashboard" />

All 7 comments

I'm interested in this too. However, I'm seeing that the component is not unmounted on a replace either. I have event listeners on some of my components that fire multiple times, depending on how the user navigates, because the original component never unmounts:

RouteA (replace) -> push A.1 (listener attaches on WillMount) -> push A.2 -> ...
RouteB (replace) -> RouteA (replace) -> push A.1 (another listener attaches, both fire on events)

Any help is greatly appreciated!

Check RN Navigator component behavior - i believe it doesn't unmount components as well...

@Mokto, @rgoldiez did you manage to find a workaround for your situation? I would like to trigger something on unmount also when the type of route is "push"

In my case, I was able to use the a 'reset' type route, which unmounts and clears the stack. This may or may not be what you're looking for. If you have code that needs to know when something new is push onto the stock (over top of your current view), you can always add an onPush handler and in that handler, broadcast an event that any concerned components listen for and take action when something is pushed on top.

Run into the same issue, had my head scratching, setting type='replace' fixed it.

<Route name="dashboard" type='replace' wrapRouter={false} component={Dashboard} title="Dashboard" />

@michshat whilst replace does demount it, it's used to replace it in the history order, which means if you use it then you can go back (especially on android back button)

@rgoldiez "you can always add an onPush handler" that's probably what I would need, but it seems that it's not an option anymore in V3, although componentWillUnmount is still not triggered with the push actions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

xnog picture xnog  路  3Comments

willmcclellan picture willmcclellan  路  3Comments

sreejithr picture sreejithr  路  3Comments

YouYII picture YouYII  路  3Comments

fgrs picture fgrs  路  3Comments