-
Notifications
You must be signed in to change notification settings - Fork 7
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
[router] Clicking on the same link twice causes the page to reload #21
Comments
For an SPA, this can lead to unwanted app state reset. That might not be clear to the user, even if it can be a wanted behaviour in some cases, but I'm not sure it's the majority of them. Maybe having this as an opt-in option? |
Hello, I recently started using this incredible router and I must comment that I am delighted with the work that the developer @thepassle has done, it really works very well and is super flexible in configurations. I have recently found myself in need of having the same behavior that you needed, that when clicking again on the same Anchor element the page would not reload. The problem is easily solved using the lit-html templates, here is an example of how I did it, I hope this helps anyone who may have this problem in the future. Greetings :) import { html } from "lit-html"
import router from "../router/router"
export function Logo() {
const handleAnchorNavigation = (e: MouseEvent) => {
const anchor = e.currentTarget as HTMLAnchorElement
const path = anchor.href
e.preventDefault()
router.navigate(path)
}
const template = html`
<a @click=${handleAnchorNavigation} href="/">
<vaadin-icon class="logo" src="/starship.svg"></vaadin-icon>
</a>
`
return html`
${template}
`
} |
This is happening because
_onAnchorClick
method hasif (this.url.href === url.href) return;
Is this intended? I think it is better to just prevent the event in this case:
The text was updated successfully, but these errors were encountered: