Skip to content

Abort navigation: throw Abort() + maybe new hook #3169

@ego-lay-atman-bay

Description

@ego-lay-atman-bay

Description

The browser has a built in way to allow developers to show an "unsaved changes" dialog when the user tries to close the page, press the forward or backward button, or click on a link.

Image

Getting it to show up when you close the page is easy and works flawlessly

import { ref } from 'vue'
import { useEventListener } from '@vueuse/core'

const isDirty = ref<boolean>(true)
useEventListener('beforeunload', (e) => {
    if (isDirty.value) {
        e.preventDefault()
    }
})

However, when using client side navigation, this dialog fails to show up whenever you use the navigation buttons or click on a link. Those only trigger when vike doesn't take control over navigation, specifically anytime the user navigates to a different website, either through browser navigation or clicking on an external link.

Here's a small demo showcasing the issue: https://github.com/ego-lay-atman-bay/vike-testing/tree/save-as

I am personally wanting to use this to keep users from accidentally closing my game (cause it's so easy to click off it and lose all your progress), but it's also just a generally useful feature for anything that has to do with user data. I think it would be very helpful if there's a way to at least tell vike to not take control over navigation temporarily in order to allow this popup to trigger.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions