After 3 years, I answer my own question. Just add a question mark at the point that makes errors. It will execute if the variable exists.
<router-link v-bind:to="{ name: 'categories.show', params: { id: post?.category_id } }">
{{ post?.category_name }}
</router-link>