Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is there a way to prevent routes from triggering? #93

Open
awei01 opened this issue Jun 16, 2016 · 6 comments
Open

is there a way to prevent routes from triggering? #93

awei01 opened this issue Jun 16, 2016 · 6 comments

Comments

@awei01
Copy link

awei01 commented Jun 16, 2016

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?

@Guria
Copy link
Collaborator

Guria commented Jun 22, 2016

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.

@christianalfoni
Copy link
Collaborator

christianalfoni commented Jun 27, 2016

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?

@awei01
Copy link
Author

awei01 commented Jun 27, 2016

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?

@christianalfoni
Copy link
Collaborator

@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 :)

@awei01
Copy link
Author

awei01 commented Jun 27, 2016

Good point... I'll play around with your suggestion. If I find anything useful, I'll post it here.

@awei01
Copy link
Author

awei01 commented Jun 28, 2016

Took some of @christianalfoni's suggestions and created a POC here: https://github.com/awei01/cerebral-module-router-POC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants