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

Feature request: onBefore #43

Closed
rottmann opened this issue Oct 24, 2019 · 1 comment
Closed

Feature request: onBefore #43

rottmann opened this issue Oct 24, 2019 · 1 comment
Labels
duplicate This issue or pull request already exists

Comments

@rottmann
Copy link

When click a link and before route to the target, it would be nice to have a global onBefore function or a onBefore on each route (or both).

E.g. if a page has modified fields, you can ask in a modal to save before leaving the page.

Currently you must implement it on your own on each link

<script>
function beforeSwitch() {
  if (isModified && alert('Leave?')) {
    const url = new URL(this.href)
    push(url.hash.substr(1)) // remove # and route to target
  }
}
</script>

<a href="#/target" on:click|preventDefault={beforeSwitch}>Link</a>
@ItalyPaleAle
Copy link
Owner

This is great timing :) I created #40 as a draft last night and would be great if you could provide feedback on that design.

(Closing as duplicate of #23 and #40)

@ItalyPaleAle ItalyPaleAle added the duplicate This issue or pull request already exists label Oct 24, 2019
freshteapot pushed a commit to freshteapot/svelte-spa-router that referenced this issue Nov 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants