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

Listen to route changes in a SPA without tight coupling framework specific router implementation #40

Open
1 of 2 tasks
eric-burel opened this issue May 21, 2021 · 0 comments
Labels
enhancement New feature or request help wanted Extra attention is needed routing

Comments

@eric-burel
Copy link
Collaborator

eric-burel commented May 21, 2021

Is your feature request related to a problem? Please describe.

In the SmartForm, we want to display a blocking popup "You have unsaved changes, are you sure you want to leave" on various events: closing the browser, changing route.

The problem is that "changing" route can happen at 2 levels:

  • in the browser. Easy to handle
  • in the SPA. That's where trouble begins.

The problem is that SPA route transition are handled by a router, which is framework specific. React Router was suffering from this limitation, and Next also suffers from it: you have to use a framework specific solution to block the route transitions.

Describe the solution you'd like

  • A pattern to tell any SPA router that we want to block route transition FIRST DRAFT OK, it triggers an event. It's app/framework responsibility to listen for those block/unblock events and add relevant behaviour for their own JS router.

For instance in React Router, that means calling history.block(), in Next, adding a listener to "beforepopstate"

Demo of a generic hook: https://gist.github.com/eric-burel/75301e2ba01967e0ec909ddf7fae5100
Work ongoing there: #31

  • A sample implemention with Next, in Vulcan Next TO BE DONE

Describe alternatives you've considered
It's possible to have Next specific solution but that creates a tight coupling which we refuse

Additional context

@eric-burel eric-burel added the enhancement New feature or request label May 21, 2021
@eric-burel eric-burel mentioned this issue May 21, 2021
20 tasks
@eric-burel eric-burel changed the title Listen to route changes in a SPA Listen to route changes in a SPA without tight coupling framework specific router implementation May 21, 2021
@eric-burel eric-burel added help wanted Extra attention is needed routing labels May 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed routing
Projects
None yet
Development

No branches or pull requests

1 participant