Open ghost opened 8 years ago
I had a previous solution before running into this problem:
Lobby.onCreated(function() {
...
FlowRouter.triggers.exit([(context, redirect, stop) => {
if(this.lobbyId && Lobbies.findOne({_id:this.lobbyId, state:{$ne:2}}))
if(!confirm(`The veto isn't over.\n\nAre you sure you want to leave this page?`))
stop()
}], {only:['lobby']})
...
})
however, this solution threw an exception because stop
was undefined sometimes... Which is why I refactored in the first place.
triggersExit only runs once before you exit your page. It's not reactive.
but I didn't actually exit, since I called stop()
...
stop()
).I am assuming this is a bug, and that triggersExit would actually be called the second time as well? :)
I hope this can either be accepted as a bug or dismissed as a misunderstanding on my part :)
I find it quite logical that triggersExit should run a 2nd time, if I stop()
it the first time, and don't navigate away
@arunoda: so the problem is that after stop
is called, flow-router thinks that we are on the new route. This aspect is not properly handled by the commit which introduces stop
: https://github.com/kadirahq/flow-router/commit/cc8b8811a2f44f65c3c91dee839d40b5fe7ac67c
So I have a partial fix which is rather hackish and leaves repeated history entries. I can make a PR but. @arunoda will probably need to fix it up given my experience with flow-router's source is just a few hours.
Fixed relatively comprehensively here: https://github.com/kadirahq/flow-router/pull/681
the titles sums it up - I'm unable to have my triggersExit function fire again, after it has been stopped.
this is my code
The trigger is fired the first time I try to leave the route, but won't trigger again before I navigate away from the route or refresh.
I'm not sure if this is a bug, or if I'm approaching this the wrong way :)