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

Possible to pass a URL to redirect function? #53

Open
mansoorkhan96 opened this issue Mar 11, 2023 · 1 comment
Open

Possible to pass a URL to redirect function? #53

mansoorkhan96 opened this issue Mar 11, 2023 · 1 comment

Comments

@mansoorkhan96
Copy link

I have a situation where i redirect users conditionally. Would love know if there is a possibility to optionally pass a URL to the redirect() function of useModal() so that it redirects to intended page instead of baseRoute.

Here is what i am trying as a word around.

const props = defineProps({ redirectUrl: String })

const { show, close, redirect } = useModal()

const handleRedirect = () => {
    if (props.redirectUrl) {
        router.get(props.redirectUrl)
    } else {
        redirect()
    }
}
<TransitionChild @after-leave="handleRedirect">
...
</TransitionChild>
@matthewknill
Copy link

matthewknill commented May 3, 2023

I think the above should work okay, however, I've found that I need to set the vnode to false otherwise it does some weird stuff where the scroll doesn't work (found by having a look at what the redirect() function does).

Try the following:

const props = defineProps({ redirectUrl: String })

const { show, close, redirect, vnode } = useModal()

const handleRedirect = () => {
    if (props.redirectUrl) {
        vnode.value = false
        router.get(props.redirectUrl)
    } else {
        redirect()
    }
}

I agree that a url parameter for the redirect function would be good though.

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

No branches or pull requests

2 participants