I'm building an app with Vue 3 and TS 4.4 and bundled with Vite 2. I've got a LoginPage.vue file with these contents:
<script lang="ts" setup>
const props = defineProps<{
message?: string;
redirectOnSubmit?: boolean;
showRegisterLink?: boolean;
}>();
console.log({ ...props });
</script>
<template>
... login form and whatnot
</template>
This component is being passed to vue-router
export const router = createRouter({
history: createWebHistory(),
routes: [
{ name: RouteName.LOGIN, path: "/login", component: LoginPage },
{ name: RouteName.REGISTER, path: "/register", component: RegisterPage },
],
});
The problem I'm having is when the login page setup script gets run, it logs this:
{ redirectOnSubmit: false, showRegisterLink: false, message: undefined }
Why are my optional boolean props being forced to false instead of undefined? Is there any way to turn this off? If I switch message to message?: boolean, it also gets switched to false.
I'd like to default these props to true if nothing is passed, but as-is there's no way for me to distinguish between passing false and omitting the props entirely.
LoginPage.vuecomponent. It's passed directly tovue-router, so it's not being passed any props. That's the problem. Vue is acting like theLoginPagecomponent is receivingredirect-on-submit="false"but really I'm not passing any props to it.