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

[WIP] Add event beforeRouteChange to confirm whether or not we want to change routes #320

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Cobrand
Copy link

@Cobrand Cobrand commented Mar 29, 2024

This is basically a shot at #204 , which is to add a function beforeRouteChange that may return true/false, if return false, prevent the history from being changed at all.

However I'm encountering a few problems, which is why it's still WIP. The biggest one:

Currently, in my implementation, beforeRouteChange is given to the Router component like so <Router {routes} {beforeRouteChange} />
But in the current codebase, push link pop are not in the component itself <script> but in the module part <script context="module".
The problem is that in theory, I need to access beforeRouteChange in push to actually confirm we want to change the route
But it is not possible to call something from "module" to the component itself, because there might be multiple components of the same kind. However, in the case of router, it does not make much sense to have multiple Router instantiated at the same time (or does it? does anyone use 2 routers?).

The question is simple: what can I do to fix this?

For now, this doesn't compile, but you may have a look at the code to see how it looks and if there are improvements. I'm posting this here a bit early to try to solve how to fix this issue.

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

Successfully merging this pull request may close these issues.

1 participant