[WIP] Add event beforeRouteChange to confirm whether or not we want to change routes #320
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 theRouter
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 routeBut 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.