Open awei01 opened 8 years ago
I can't see a good way to prevent such case. Link component triggers signals, not routes. You can add an action to your signal which will check that navigation currently unwanted. But from UX point of view I would recommend just have smart form state restore if user returns back after unwanted navigation.
I would suggest the same approach as "authentication" again.
module.addSignals({
homeClicked: preventUnfinished(homeClicked)
})
This factory has the logic for ensuring that something started is also finished:
function preventUnfinished(chain) {
return [
isNotFinished, {
formA: [notifyFormAError],
formB: [notifyFormBError],
otherwise: chain
}
];
}
This will actually also notify when the url is manually changed... which is not the case typically in these scenarios. The debugger will also show very clearly what is happening on these scenarios. Does that make sense?
This makes sense. But, now it seems like any routeable signal will require these factories to work properly.
Just throwing out another idea: What if the cerebral-module-router
had a services like preventRouting
and stopPreventRouting
which you could turn on and off. Then in my module which manages the form state, i can call preventRouting
upon form change and then stopPreventRouting
upon form completion?
@awei01 That is an interesting suggestion! Though I believe you would still need to use factories on all the routed signals, because I suppose you want to give an error if the user tries to route and it is prevented? Hm hm :)
Good point... I'll play around with your suggestion. If I find anything useful, I'll post it here.
Took some of @christianalfoni's suggestions and created a POC here: https://github.com/awei01/cerebral-module-router-POC
Hi, I'm wondering if there's a way to prevent routes from triggering or addressbar url change.
Use case: Someone is filling out a form and doesn't save. But then they click on a different link or change address in address bar. Is there a best-practice way to handle this?