'Vue3 - Routes if page doesn't exist with dynamic routes not working with my 404?

I am using Vue3 and have my Router setup for detail pages. Any title returns the same data and 404 is being ignored even after adding the regEx inside the routes.

Routes:

import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router";
import HomeView from "../views/HomeView.vue";
import ErrorView from "../views/ErrorView.vue";

const routes: Array<RouteRecordRaw> = [
  {
    path: "/",
    name: "home",
    component: HomeView,
  },
  {
    path: "/about",
    name: "about",
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () =>
      import(/* webpackChunkName: "about" */ "../views/AboutView.vue"),
  },
  {
    path: "/article/:slug",
    name: "article",
    component: () =>
      import(/* webpackChunkName: "article" */ "../views/ArticleView.vue"),
  },
  {
    path: "/404",
    name: "PageNotExist",
    component: () => import("../views/ErrorView.vue"),
  },
  {
    path: "/:catchAll(.*)", // Unrecognized path automatically matches 404
    redirect: "/404",
  },
];

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes,
});

export default router;

Article:

<template>
  <div>
    <h1>{{ data.title }}</h1>
    <h3>{{ data.textarea }}</h3>
  </div>
</template>

<script lang="ts">
import { useSanityFetcher } from "vue-sanity";
import { defineComponent } from "vue";

export default defineComponent({
  name: "ArticleView",
  setup: () => {
    const articleQuery = `*[_type == "article"][0] {
        title,
        textarea,
    }`;

    const options = {
      listen: true,
      clientOnly: true,
    };

    const { data } = useSanityFetcher<object>(articleQuery, options);

    return { data };
  },
});
</script>


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source